home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 230_01 / parser.bun < prev    next >
Text File  |  1987-05-25  |  101KB  |  4,182 lines

  1. : To unbundle, sh this file
  2. echo unbundling parser.y 1>&2
  3. cat >parser.y <<'End'
  4. /*
  5.     Little Smalltalk Class method syntax
  6.         
  7.         differs from smalltalk-80 slightly
  8.  
  9.             class heading is different
  10.             vertical bar must appear between methods
  11.             syntax for primitives is different
  12.  
  13. */
  14.  
  15. /*      literals        */
  16. %token LITNUM LITFNUM LITCHAR LITSTR LITSYM
  17.  
  18. /*      basic objects   */
  19. %token CLASS ASSIGN BINARY PRIMITIVE NAMEDPRIM
  20.  
  21. /*      types of variables */
  22. %token PSEUDO UPPERCASEVAR LOWERCASEVAR COLONVAR KEYWORD
  23.  
  24. /*      one character symbols */
  25. %token LP RP LB RB PERIOD BAR MBAR SEMI UPARROW PS MINUS PE
  26. /*     (  )  [  ]  .      |   ^|   ;    ^       #  -     > */
  27.  
  28. %{
  29. # include "env.h"
  30. # include "drive.h"
  31. # include "parser.h"
  32. %}
  33.  
  34. %union {
  35.     struct litlist         *a;
  36.     struct blockstruct     *b;
  37.     char             *c;
  38.     struct exprstruct     *e;
  39.     int               i;
  40.     struct keylist         *k;
  41.     struct classstruct     *l;
  42.     struct methodstruct     *m;
  43.     struct objstruct     *o;
  44.     enum pseuvars          p;
  45.     struct primlist     *r;
  46.     struct statestruct     *s;
  47.     struct litstruct     *t;
  48.     struct primstruct     *u
  49.     }
  50.  
  51. %{
  52. extern struct blockstruct *mkblock();
  53. extern struct classstruct *mkclass();
  54. extern struct varstruct *mkvar(), *addvlist(), *invlist();
  55. extern struct methodstruct *mkmethod();
  56. extern struct exprstruct *mkexpr(), *mkkey();
  57. extern struct keylist *mkklist();
  58. extern struct statestruct *mkstate();
  59. extern struct objstruct *mkobj();
  60. extern struct primstruct *mkprim();
  61. extern struct primlist *addprim();
  62. extern struct litstruct *mklit();
  63. extern struct litlist *addlit();
  64. extern char   *bincat();
  65.  
  66. struct varstruct *instvars;
  67. struct varstruct *contextvars;
  68.  
  69. int bytetop = 0;
  70. uchar bytearray[1000];
  71.  
  72. YYSTYPE e;
  73. int errorcount = 0;
  74. %}
  75.  
  76. %type <a> litarray
  77. %type <b> block
  78. %type <c> CLASS KEYWORD LOWERCASEVAR UPPERCASEVAR COLONVAR LITSYM LITSTR
  79. %type <c> BINARY BAR MINUS UPARROW PE
  80. %type <c> classname binarysym binarychar
  81. %type <c> LITFNUM fliteral
  82. %type <e> pattern expression cexpression binary unary
  83. %type <e> kcontinuation bcontinuation ucontinuation
  84. %type <i> LITCHAR LITNUM PRIMITIVE NAMEDPRIM
  85. %type <i> tempvars cvarlist namelist barglist nliteral
  86. %type <k> keypattern keywordlist
  87. %type <l> super classheading
  88. %type <m> method methodlist
  89. %type <o> primary
  90. %type <p> PSEUDO
  91. %type <r> objlist
  92. %type <s> statelist statement sexpression opmessagelist
  93. %type <s> bstatelist bstatement bexpression
  94. %type <t> literal iliteral aliteral
  95. %type <u> primitive
  96.  
  97.  
  98. %start file
  99.  
  100. %%
  101. file    :       classdef
  102.         |       file classdef
  103.         ;
  104.  
  105. classdef:       classheading lb methodlist RB
  106.             {if (errorcount == 0) genclass($1, $3);}
  107.         ;
  108.  
  109. lb      :       LB
  110.         |       error   {if ((yytext[0] == ':') ||
  111.                              isalpha(yytext[0])) expect(":SuperClass");
  112.                          else expect("open brace [");}
  113.         ;
  114.  
  115. classheading:   class super instancevars {$$ = $2;}
  116.         ;
  117.  
  118. class   :       CLASS
  119.         |       error                   {expect("keyword Class");}
  120.         ;
  121.  
  122. super   :       classname                  {$$ = mkclass($1, (char *) 0);}
  123.         |       classname COLONVAR        {$$ = mkclass($1, $2);}
  124.         |       error                   {expect("Classname :Superclass");
  125.                                          $$ = mkclass("Error", (char *) 0);}
  126.         ;
  127.  
  128. classname:    UPPERCASEVAR
  129.     |    CLASS
  130.     ;
  131.  
  132. instancevars:   /* empty */
  133.         |       bar instvarlist bar
  134.         ;
  135.  
  136. instvarlist:    LOWERCASEVAR            {addinst($1);}
  137.         |       instvarlist LOWERCASEVAR    {addinst($2);}
  138.         |       error                       {expect("instance variable");}
  139.         ;
  140.  
  141. methodlist:     method            
  142.         |       methodlist MBAR method
  143.             {$3->nextmethod = $1; $$ = $3;}
  144.         ;
  145.  
  146. method  :       pattern tempvars statelist op
  147.             {deltemps($2); $$ = mkmethod($1, $2, $3);}
  148.         ;
  149.  
  150. pattern:        keypattern
  151. {$$ = mkkey((struct exprstruct *) 0, $1);}
  152.         |       binarysym argvariable
  153. {$$ = mkexpr((struct exprstruct *) 0, bincmd, $1, (struct exprstruct *) 0);}
  154.         |       LOWERCASEVAR
  155. {$$ = mkexpr((struct exprstruct *) 0, uncmd, $1, (struct exprstruct *) 0);}
  156.         |       error                   {expect("method pattern");
  157. $$ = mkexpr((struct exprstruct *) 0, uncmd, "", (struct exprstruct *) 0);}
  158.         ;
  159.  
  160. keypattern:     KEYWORD argvariable
  161. {$$ = mkklist((struct keylist *) 0, $1, (struct exprstruct *) 0);}
  162.         |       keypattern KEYWORD argvariable
  163. {$$ = mkklist($1, $2, (struct exprstruct *) 0);}
  164.         ;
  165.  
  166. argvariable:      LOWERCASEVAR            {addtemp($1, argvar);}
  167.         |         error                   {expect("argument variable");}
  168.         ;
  169.  
  170. tempvars:       /* empty */             {$$ = 0;}
  171.         |       bar namelist bar        {$$ = $2;}
  172.         ;
  173.  
  174. bar     :       BAR
  175.         |       MBAR
  176.         |       error                   {expect("| (vertical bar)");}
  177.         ;
  178.  
  179. namelist:       tvariable               {$$ = 1;}
  180.         |       namelist tvariable      {$$ = $1 + 1;}
  181.         ;
  182.  
  183. tvariable:      LOWERCASEVAR               {addtemp($1, tempvar);}
  184.         ;
  185.  
  186. statelist:    statement            {$$ = $1;}
  187.         |    statelist PERIOD statement    {$3->nextstate = $1; $$ = $3;}
  188.         ;
  189.  
  190. op    :    /* empty - optional period */
  191.     |    PERIOD
  192.     ;
  193.  
  194. statement:    UPARROW sexpression    {$$ = mkstate(upar, (char *) 0, $2);}
  195.     |    sexpression
  196.     ;
  197.  
  198. sexpression:    LOWERCASEVAR ASSIGN sexpression
  199.                 {$$ = mkstate(asgn, $1, $3);}
  200.     |    cexpression    
  201.     {$$ = mkstate(expr, (char *) 0, (struct statestruct *) $1);}
  202.     ;
  203.  
  204. cexpression:    expression
  205.     |    kcontinuation    {$$ = mkexpr($1, semiend, 0, 0);}
  206.     ;
  207.  
  208. kcontinuation:    bcontinuation
  209.     |    bcontinuation keywordlist {$$ = mkkey($1, $2);}
  210.     ;
  211.  
  212. bcontinuation:    ucontinuation
  213.     |    bcontinuation binarysym unary
  214.             {$$ = mkexpr($1, bincmd, $2, $3);}
  215.     ;
  216.  
  217. ucontinuation:    cexpression SEMI    {$$ = mkexpr($1, semistart, 0, 0);}
  218.     |    ucontinuation LOWERCASEVAR
  219.         {$$ = mkexpr($1, uncmd, $2, (struct exprstruct *) 0);}
  220.     ;
  221.  
  222. expression:     binary            {$$ = $1;}
  223.         |       binary keywordlist    {$$ = mkkey($1, $2);}
  224.         ;
  225.  
  226. keywordlist:    KEYWORD binary        
  227.             {$$ = mkklist((struct keylist *) 0, $1, $2);}
  228.         |       keywordlist KEYWORD binary
  229.             {$$ = mkklist($1, $2, $3);}
  230.         ;
  231.  
  232. binary  :       unary            {$$ = $1;}
  233.         |       binary binarysym unary    {$$ = mkexpr($1, bincmd, $2, $3);}
  234.         ;
  235.  
  236. binarysym:    binarychar        {$$ = $1;}
  237.     |    binarychar binarychar    {$$ = bincat($1, $2);}
  238.     ;
  239.  
  240. binarychar:      BINARY
  241.         |       BAR
  242.         |       MINUS
  243.         |       UPARROW
  244.     |    PE            
  245.         ;
  246.  
  247. unary   :       primary            
  248.         {$$ = mkexpr((struct exprstruct *) 0, reccmd, (char *) 0,
  249.                     (struct exprstruct *) $1);}
  250.         |       unary LOWERCASEVAR
  251.         {$$ = mkexpr($1, uncmd, $2, (struct exprstruct *) 0);}
  252.         ;
  253.  
  254. primary :    classname        {e.c = $1; $$ = mkobj(classobj, &e);}
  255.         |       LOWERCASEVAR        {e.c = $1; $$ = mkobj(varobj, &e);}
  256.         |       literal            {e.t = $1; $$ = mkobj(litobj, &e);}
  257.         |       PSEUDO            {e.p = $1; $$ = mkobj(pseuobj, &e);}
  258.     |    primitive        {e.u = $1; $$ = mkobj(primobj, &e);}
  259.         |       LP sexpression RP    {e.s = $2; $$ = mkobj(exprobj, &e);}
  260.     |    block             {e.b = $1; $$ = mkobj(blockobj, &e);}
  261.         ;
  262.  
  263. primitive:    PRIMITIVE LITNUM objlist PE
  264.                     {$$ = mkprim($2, $3);}
  265.     |    NAMEDPRIM objlist PE
  266.                     {$$ = mkprim($1, $2);}
  267.     ;
  268.  
  269. objlist :    /* empty */        {$$ = (struct primlist *) 0;}
  270.     |    objlist primary        {$$ = addprim($1, $2);}
  271.     ;
  272.  
  273. block    :    LB barglist opmessagelist RB
  274.                     {$$ = mkblock($2, $3);
  275.                     deltemps($2);}
  276.     ;
  277.  
  278. barglist :       /* empty */             {$$ = 0;}
  279.         |       cvarlist BAR            {$$ = $1;}
  280.         ;
  281.  
  282. cvarlist:       COLONVAR               {addtemp($1, argvar); $$ = 1;}
  283.         |       cvarlist COLONVAR      {addtemp($2, argvar); $$ = $1 + 1;}
  284.         ;
  285.  
  286. opmessagelist:    bstatelist bstatement     {$2->nextstate = $1; $$ = $2;}
  287.     |    bstatement         {$$ = $1;}
  288.     ;
  289.  
  290. bstatement:    UPARROW sexpression     {$$ = mkstate(blkupar, (char *) 0, $2);}
  291.     |    bexpression        {$$ = mkstate(upar, (char *) 0, $1);}
  292.     ;
  293.  
  294. bexpression:    /* empty */
  295. {e.p = nilvar;
  296. $$ = mkstate(expr, (char *) 0,
  297. (struct statestruct *) mkexpr((struct exprstruct *) 0, reccmd, (char *) 0,
  298.     (struct exprstruct *) mkobj(pseuobj, &e)));}
  299.     |    sexpression        {$$ = $1;}
  300.     ;
  301.  
  302. bstatelist:     sexpression PERIOD    {$$ = $1;}
  303.         |       bstatelist sexpression PERIOD
  304.             {$2->nextstate = $1; $$ = $2;}
  305.         ;
  306.  
  307. literal :       iliteral                {$$ = $1;}
  308.         |       alitstart litarray RP   {e.a = $2; $$ = mklit(arlit, &e);}
  309.         ;
  310.  
  311. alitstart:      PS LP
  312.         ;
  313.  
  314. iliteral:    fliteral        {e.c = $1; $$ = mklit(fnumlit, &e);}
  315.     |    nliteral        {e.i = $1; $$ = mklit(numlit, &e);}
  316.     |       LITCHAR                 {e.i = $1; $$ = mklit(charlit, &e);}
  317.         |       LITSTR                  {e.c = $1; $$ = mklit(strlit, &e);}
  318.         |       LITSYM                  {e.c = $1; $$ = mklit(symlit, &e);}
  319.         |       PS LB bytearray RB      {bytearray[bytetop] = '\0';
  320.                                          $$ = mklit(bytelit, &e);}
  321.         ;
  322.  
  323. fliteral:    LITFNUM            {$$ = $1;}
  324.     |     MINUS LITFNUM        {$$ = bincat("-", $2);}
  325.     ;
  326.  
  327. nliteral:    LITNUM            {$$ = $1;}
  328.     |    MINUS LITNUM        {$$ = - $2;}
  329.     ;
  330.  
  331. aliteral:       iliteral                {$$ = $1;}
  332.         |       LOWERCASEVAR            {e.c = $1; $$ = mklit(symlit, &e);}
  333.         |       UPPERCASEVAR            {e.c = $1; $$ = mklit(symlit, &e);}
  334.     |    KEYWORD            {e.c = $1; $$ = mklit(symlit, &e);}
  335.     |    COLONVAR        {e.c = $1; $$ = mklit(symlit, &e);}
  336.     |    CLASS            {e.c = $1; $$ = mklit(symlit, &e);}
  337.         |       binarysym               {e.c = $1; $$ = mklit(symlit, &e);}
  338.         |       ias litarray RP         {e.a = $2; $$ = mklit(arlit, &e);}
  339.         ;
  340.  
  341. ias     :       PS LP
  342.         |       LP
  343.         ;
  344.  
  345. litarray:       /* empty */             {$$ = (struct litlist *) 0;}
  346.         |       litarray aliteral       {$$ = addlit($1, $2);}
  347.         ;
  348.  
  349. bytearray:      LITNUM                  {bytetop = 0;
  350.                                          bytearray[bytetop++] = itouc($1);}
  351.         |       bytearray LITNUM        {bytearray[bytetop++] = itouc($2);}
  352.         ;
  353. %%
  354. # include <stdio.h>
  355.  
  356. char *filename;
  357. FILE *fp;
  358. FILE *ofd;
  359.  
  360. # include "lex.yy.c"
  361.  
  362. main(argc, argv)
  363. int argc;
  364. char **argv;
  365. {    
  366.     if (argc != 2) quiter("parser: wrong number of arguments");
  367.     filename = argv[1];
  368.     fp = fopen(filename, "r");
  369.     if (fp == NULL) {
  370.         yerr("cannot open input file %s", filename);
  371.         quiter("parser quits");
  372.         }
  373.     ofd = stdout;
  374.     return(yyparse());
  375. }
  376.  
  377. quiter(s) char *s; {fprintf(stderr,"%s\n", s); exit(1);}
  378.  
  379. yywarn(s, v) char *s, *v; {
  380.    fprintf(stderr, "%s: line %d: Warning ", filename, linenum);
  381.    fprintf(stderr, s, v);
  382.    fprintf(stderr,"\n");
  383. }
  384.  
  385. yyerror(s) char *s; {yerr(s, "");}
  386.  
  387. yerr(s, v)
  388. char *s, *v;
  389. {
  390.    fprintf(stderr, "%s: line %d: ", filename, linenum);
  391.    fprintf(stderr, s, v);
  392.    fprintf(stderr,"\n");
  393.    if (errorcount++ > 10) quiter("too many errors, goodby");
  394. }
  395.  
  396. expect(str) char *str;
  397. {  char buffer[100];
  398.  
  399.    sprintf(buffer,"Expected %%s found %s", yytext);
  400.    yerr(buffer, str);
  401. }
  402.  
  403. int yywrap() { return(1);}
  404.  
  405. char *alloc(size) int size;      /* allocate a block of storage */
  406. {  char *p, *malloc();
  407.  
  408.    p = malloc( (unsigned) size);
  409.    if (p == (char *) 0) yyerror("out of free space");
  410.    return(p);
  411. }
  412.  
  413. char *bincat(s1, s2)
  414. char *s1, *s2;
  415. {    char *p;
  416.  
  417.     p = alloc(strlen(s1) + strlen(s2) + 1);
  418.     strcpy(p, s1);
  419.     strcat(p, s2);
  420.     return(p);
  421. }
  422. End
  423. echo unbundling parser.lex 1>&2
  424. cat >parser.lex <<'End'
  425. %{
  426. /*
  427.         Little Smalltalk lexical analyzer
  428. */
  429. # include <math.h>
  430. # include "primnum.h"
  431.  
  432. # undef input
  433. # undef unput
  434.  
  435. double atof();
  436. int linenum = 1;
  437. %}
  438. %%
  439. [ \t]+                          {;}
  440. \n                              {linenum++;}
  441. \"                              {readcomment();}
  442. ":="                            {return(ASSIGN);}
  443. "<-"                            {return(ASSIGN);}
  444. Class                           {return(lexsave(CLASS));}
  445. self                            {yylval.p = selfvar;  return(PSEUDO);}
  446. selfProcess            {yylval.p = procvar;  return(PSEUDO);}
  447. super                           {yylval.p = supervar; return(PSEUDO);}
  448. nil                             {yylval.p = nilvar;   return(PSEUDO);}
  449. true                            {yylval.p = truevar;  return(PSEUDO);}
  450. false                           {yylval.p = falsevar; return(PSEUDO);}
  451. smalltalk                       {yylval.p = smallvar; return(PSEUDO);}
  452. \$.                             {yylval.i = yytext[1]; return(LITCHAR);}
  453. #                               {return(PS);}
  454. [0-9]+r-?[0-9A-Z]+(\.[0-9A-Z]+)?(e[-+]?[0-9]+)? {return(lexsave(LITFNUM));}
  455. [0-9]+                          {yylval.i = atoi(yytext); return(LITNUM);}
  456. [0-9]+(\.[0-9]+)?(e[-+]?[0-9]+)?   {return(lexsave(LITFNUM));}
  457. '[^']*'                         {char c; unput(c = input());
  458.                                  if (c == '\'') yymore();
  459.                                  else return(lexlstr());}
  460. [a-zA-Z0-9]+:?                  {return(varlex());}
  461. :[a-zA-Z0-9]+                   {return(slexsave(COLONVAR));}
  462. #[^ \t\n.()\[]+                 {return(slexsave(LITSYM));}
  463. "-"                             {return(lexsave(MINUS));}
  464. "("                             {return(LP);}
  465. ")"                             {return(RP);}
  466. "["                             {return(LB);}
  467. "]"                             {return(RB);}
  468. "."                             {return(PERIOD);}
  469. ^"|"                {return(lexsave(MBAR));}
  470. ^"!"                {return(lexsave(MBAR));}
  471. "|"                             {return(lexsave(BAR));}
  472. "!"                             {return(lexsave(BAR));}
  473. ";"                             {return(SEMI);}
  474. "^"                             {return(lexsave(UPARROW));}
  475. ">"                {return(lexsave(PE));}
  476. [^ \t\nA-Za-z0-9]               {return(lexsave(BINARY));}
  477. "<primitive"               {return(PRIMITIVE);}
  478. "<"[a-zA-Z0-9]+            {yylval.i = prim_number(&yytext[1]); return(NAMEDPRIM);}
  479. %%
  480. static int ocbuf = 0;
  481. static int pbbuf[400];
  482.  
  483. static int input()
  484. {    int c;
  485.  
  486.     if (ocbuf) {c = pbbuf[--ocbuf]; }
  487.     else {
  488.         c = getc(fp);
  489.         if (c == EOF) c = 0;
  490.         }
  491.     return(c);
  492. }
  493.  
  494. static unput(c)
  495. char c;
  496. {
  497.     if (c) pbbuf[ocbuf++] = c;
  498. }
  499.  
  500. # include <ctype.h>
  501.  
  502. static readcomment()
  503. {  char c;
  504.  
  505.    while ((c = input()) && c != '\"')
  506.     if (c == '\n') linenum++;
  507.    if (!c) yyerror("unterminated comment");
  508. }
  509.  
  510. char *walloc(s) char *s;
  511. {  char *p, *malloc();
  512.  
  513.    p = malloc((unsigned) (strlen(s) + 1));
  514.    if (p == (char *) 0) yyerror("out of variable string space");
  515.    strcpy(p, s);
  516.    return(p);
  517. }
  518.  
  519. static int slexsave(type)
  520. int type;
  521. {
  522.  
  523.     yylval.c = walloc(&yytext[1]);
  524.     if (yylval.c == 0) yerr("cannot create symbol %s", yytext);
  525.     return(type);
  526. }
  527.  
  528. static int lexsave(type)
  529. int type;
  530. {
  531.  
  532.     yylval.c = walloc(yytext);
  533.     if (yylval.c == 0) yerr("cannot create string %s", yytext);
  534.     return(type);
  535. }
  536.  
  537. static int varlex()
  538. {
  539.  
  540.    lexsave(0);
  541.    if (yytext[yyleng-1] == ':') return(KEYWORD);
  542.    else if (islower(yytext[0])) return(LOWERCASEVAR);
  543.    else return(UPPERCASEVAR);
  544. }
  545.  
  546. static int lexlstr()
  547. {  char *p, *q;
  548.  
  549.    yylval.c = p = walloc(&yytext[1]);
  550.    *(p + yyleng -2) = '\0';
  551.    return(LITSTR);
  552. }
  553.  
  554. static int prim_number(name)
  555. char *name;
  556. {    struct prim_names *p;
  557.  
  558.     for (p = prim_table; *(p->p_name); p++) {
  559.         if (strcmp(p->p_name, name) == 0)
  560.             return(p->p_number);
  561.         }
  562.     yerr("unknown primitive name %s", name);
  563.     return(0);
  564. }
  565. End
  566. echo unbundling parse1.c 1>&2
  567. cat >parse1.c <<'End'
  568. /*
  569.     Little Smalltalk
  570.         pass 1 of the parser
  571.  
  572.         timothy a. budd, 10/84
  573.  
  574. */
  575. /*
  576.     The source code for the Little Smalltalk System may be freely
  577.     copied provided that the source of all files is acknowledged
  578.     and that this condition is copied with each file.
  579.  
  580.     The Little Smalltalk System is distributed without responsibility
  581.     for the performance of the program and without any guarantee of
  582.     maintenance.
  583.  
  584.     All questions concerning Little Smalltalk should be addressed to:
  585.  
  586.         Professor Tim Budd
  587.         Department of Computer Science
  588.         Oregon State University
  589.         Corvallis, Oregon
  590.         97331
  591.         USA
  592. */
  593. # include <stdio.h>
  594. # include "env.h"
  595. # include "drive.h"
  596. # include "parser.h"
  597. # include "y.tab.h"
  598.  
  599. extern char *alloc();
  600.  
  601. int maxcontext = 0;
  602.  
  603. struct classstruct *mkclass(classname, supername)
  604. char *classname, *supername;
  605. {    struct classstruct *new;
  606.     struct varstruct *mkvar(), *addvlist();
  607.  
  608.     new = structalloc(classstruct);
  609.     new->name = classname;
  610.     if (supername)
  611.         new->super = supername;
  612.     else new->super = walloc("Object");
  613.     instvars = (struct varstruct *) 0;
  614.     contextvars = (struct varstruct *) 0;
  615.     maxcontext = 0;
  616.     addtemp("_self", (enum vartypes) 0);
  617.     return(new);
  618. }
  619.  
  620. struct varstruct *mkvar(text, vtype) char *text; enum vartypes vtype;
  621. {  struct varstruct *p;
  622.  
  623.    p = structalloc(varstruct);
  624.    p->vtype = vtype;
  625.    p->text = text;
  626.    p->nextvar = (struct varstruct *) 0;
  627.    p->position = 17;
  628.    return(p);
  629. }
  630.  
  631. struct varstruct *addvlist(varnode, vlist)
  632. struct varstruct *varnode, *vlist;
  633. {
  634.    varnode->nextvar = vlist;
  635.    if (vlist) varnode->position = 1 + vlist->position;
  636.    else varnode->position = 0;
  637.    return(varnode);
  638. }
  639.  
  640. addtemp(name, vtype)
  641. char *name;
  642. enum vartypes vtype;
  643. {
  644.     contextvars = addvlist(mkvar(name, vtype), contextvars);
  645.     if (contextvars->position > maxcontext)
  646.         maxcontext = contextvars->position;
  647. }
  648.  
  649. struct varstruct *invlist(varnode, name)
  650. struct varstruct *varnode;
  651. char *name;
  652. {
  653.     for ( ; varnode; varnode = varnode->nextvar)
  654.         if (strcmp(varnode->text, name) == 0)
  655.             return(varnode);
  656.     return((struct varstruct *) 0);
  657. }
  658.  
  659. struct methodstruct *mkmethod(pat, temps, state)
  660. struct exprstruct *pat;
  661. int temps;
  662. struct statestruct *state;
  663. {    struct methodstruct *new;
  664.     int i;
  665.  
  666.     new = structalloc(methodstruct);
  667.     new->pattern = pat;
  668.     new->numtempvars = temps;
  669.     new->states = state;
  670.     new->nextmethod = (struct methodstruct *) 0;
  671.     switch(pat->cmdtype) {
  672.         case uncmd: i = 0; break;
  673.         case bincmd: i = 1; break;
  674.         case keycmd: i = keycount(pat->cc.keys); break;
  675.         }
  676.     deltemps(i);
  677.     return(new);
  678. }
  679.  
  680. keycount(kl)
  681. struct keylist *kl;
  682. {
  683.     if (kl->nextkey)
  684.         return(1 + keycount(kl->nextkey));
  685.     else return(1);
  686. }
  687.  
  688. struct statestruct *mkstate(type, name, sexpr)
  689. enum statetypes type;
  690. char *name;
  691. struct statestruct *sexpr;
  692. {    struct statestruct *new;
  693.     struct varstruct *v;
  694.  
  695.     new = structalloc(statestruct);
  696.     new->statetype = type;
  697.     new->nextstate = (struct statestruct *) 0;
  698.     switch(type) {
  699.         case upar: case blkupar:
  700.             new->nn.stateexpr = sexpr;
  701.             break;
  702.         case expr:
  703.             new->nn.cmd = (struct exprstruct *) sexpr;
  704.             break;
  705.         case asgn:
  706.             new->nn.stateexpr = sexpr;
  707.             v = invlist(instvars, name);
  708.             if (v) {
  709.                 new->statetype = iasgn;
  710.                 new->mm.varpos = v->position;
  711.                 break;
  712.                 }
  713.             v = invlist(contextvars, name);
  714.             if (v) {
  715.                 new->statetype = casgn;
  716.                 new->mm.varpos = v->position;
  717.                 break;
  718.                 }
  719.         default:
  720.             yyerror("unknown variable or case in mkstate");
  721.         }
  722.     return(new);
  723. }
  724.  
  725. struct exprstruct *mkexpr(receiver, type, name, args)
  726. struct exprstruct *receiver, *args;
  727. enum cmdtypes type;
  728. char *name;
  729. {    struct exprstruct *new;
  730.  
  731.     new = structalloc(exprstruct);
  732.     new->cmdtype = type;
  733.     new->cmdname = name;
  734.     new->receiver = receiver;
  735.     switch(type) {
  736.         case reccmd:
  737.             new->cc.recobj = (struct objstruct *) args;
  738.             break;
  739.         case uncmd:
  740.             break;
  741.         case bincmd:
  742.             new->cc.argument = args;
  743.             break;
  744.         case keycmd:
  745.             new->cc.keys = (struct keylist *) args;
  746.             break;
  747.         }
  748.     return(new);
  749. }
  750.  
  751. struct keylist *mkklist(kl, kw, ka)
  752. struct keylist *kl;
  753. char *kw;
  754. struct exprstruct *ka;
  755. {    struct keylist *new;
  756.  
  757.     new = structalloc(keylist);
  758.     new->keyword = kw;
  759.     new->arg = ka;
  760.     new->nextkey = kl;
  761.     return(new);
  762. }
  763.     
  764. mkkname(kl, kb)
  765. struct keylist *kl;
  766. char *kb;
  767. {
  768.     if (kl->nextkey)
  769.         mkkname(kl->nextkey, kb);
  770.     strcat(kb, kl->keyword);
  771. }
  772.  
  773. struct exprstruct *mkkey(receiver, keywordlist)
  774. struct exprstruct *receiver;
  775. struct keylist *keywordlist;
  776. {    char kbuffer[500];
  777.  
  778.     kbuffer[0] = '\0';
  779.     mkkname(keywordlist, kbuffer);
  780.     return(mkexpr(receiver, keycmd, walloc(kbuffer),
  781.         (struct exprstruct *) keywordlist));
  782. }
  783.  
  784. struct objstruct *mkobj(type, info)
  785. enum objtypes type;
  786. YYSTYPE *info;
  787. {    struct objstruct *new;
  788.     struct varstruct *v;
  789.     struct litstruct *mklit();
  790.  
  791.     new = structalloc(objstruct);
  792.     new->objtype = type;
  793.     switch(type) {
  794.         case classobj:
  795.             new->ee.litinfo = mklit(symlit, info);
  796.             break;
  797.         case varobj:
  798.             v = invlist(instvars, info->c);
  799.             if (v) {
  800.                 new->objtype = instvarobj;
  801.                 new->ee.varoffset = v->position;
  802.                 return(new);
  803.                 }
  804.             v = invlist(contextvars, info->c);
  805.             if (v) {
  806.                 new->objtype = contvarobj;
  807.                 new->ee.varoffset = v->position;
  808.                 return(new);
  809.                 }
  810.             yerr("unknown variable %s", info->c);
  811.             break;
  812.         case litobj:
  813.             new->ee.litinfo = info->t;
  814.             break;
  815.         case pseuobj:
  816.             new->ee.pseuinfo = info->p;
  817.             break;
  818.         case primobj:
  819.             new->ee.priminfo = info->u;
  820.             break;
  821.         case exprobj:
  822.             new->ee.stateinfo = info->s;
  823.             break;
  824.         case blockobj:
  825.             new->ee.blockinfo = info->b;
  826.             break;
  827.     }
  828.     return(new);
  829. }
  830.  
  831. struct blockstruct *mkblock(numargs, bstates)
  832. int numargs;
  833. struct statestruct *bstates;
  834. {    struct blockstruct *new;
  835.     int i;
  836.  
  837.     new = structalloc(blockstruct);
  838.     new->numargs = numargs;
  839.     if (contextvars)
  840.         i = (contextvars->position - numargs) +1;
  841.     else i = 1;
  842.     new->arglocation = i;
  843.     new->bstates = bstates;
  844.     return(new);
  845. }
  846.  
  847.  
  848. struct primstruct *mkprim(pnum, plist)
  849. struct primlist *plist;
  850. int pnum;
  851. {    struct primstruct *new;
  852.  
  853.     new = structalloc(primstruct);
  854.     new->primnumber = pnum;
  855.     new->plist = plist;
  856.     return(new);
  857. }
  858.  
  859. struct primlist *addprim(plist, prim)
  860. struct primlist *plist;
  861. struct objstruct *prim;
  862. {    struct primlist *new;
  863.  
  864.     new = structalloc(primlist);
  865.     new->nextprim = plist;
  866.     new->pobject = prim;
  867.     return(new);
  868. }
  869.  
  870. struct litlist *addlit(list, lit)
  871. struct litlist *list;
  872. struct litstruct *lit;
  873. {    struct litlist *new;
  874.  
  875.     new = structalloc(litlist);
  876.     new->litele = lit;
  877.     new->nextlit = list;
  878.     return(new);
  879. }
  880.  
  881. struct litstruct *mklit(littype, e)
  882. enum littypes littype;
  883. YYSTYPE *e;
  884. {  struct litstruct *p;
  885.  
  886.     p = structalloc(litstruct);
  887.     p->littype = littype;
  888.     switch(littype) {
  889.         case numlit:  p->ll.litint = e->i; break;
  890.         case fnumlit: p->ll.litstr = e->c; break;
  891.         case charlit: p->ll.litchar = (char) e->i; break;
  892.         case strlit:  p->ll.litstr = e->c; break;
  893.         case symlit:  p->ll.litsym = e->c; break;
  894.         case arlit:   p->ll.litarry = e->a; break;
  895.           }
  896.     return(p);
  897. }
  898.  
  899. deltemps(n)
  900. int n;
  901. {
  902.     while (n--) {
  903.         contextvars = contextvars->nextvar;
  904.         }
  905. }
  906. End
  907. echo unbundling parse2.c 1>&2
  908. cat >parse2.c <<'End'
  909. /*
  910.     Little Smalltalk
  911.         pass 2 of the parser
  912.  
  913.         timothy a. budd, 10/84
  914.  
  915. */
  916. /*
  917.     The source code for the Little Smalltalk System may be freely
  918.     copied provided that the source of all files is acknowledged
  919.     and that this condition is copied with each file.
  920.  
  921.     The Little Smalltalk System is distributed without responsibility
  922.     for the performance of the program and without any guarantee of
  923.     maintenance.
  924.  
  925.     All questions concerning Little Smalltalk should be addressed to:
  926.  
  927.         Professor Tim Budd
  928.         Department of Computer Science
  929.         Oregon State University
  930.         Corvallis, Oregon
  931.         97331
  932.         USA
  933. */
  934. # include <stdio.h>
  935. # include "env.h"
  936. # include "drive.h"
  937. # include "cmds.h"
  938. # include "parser.h"
  939. # include "y.tab.h"
  940.  
  941. extern int maxcontext;
  942. extern char *filename;
  943. extern FILE *ofd;
  944.  
  945. static int inblock = 0;
  946. static int topstack = 0;
  947. static int maxstack = 0;
  948. # define bumpstk() if (++topstack > maxstack) maxstack = topstack
  949. # define popstk(i) topstack -= i
  950.  
  951. genclass(clinfo, mlist)
  952. struct classstruct *clinfo;
  953. struct methodstruct *mlist;
  954. {    int i;
  955.     struct methodstruct *m, *n;
  956.  
  957.     topstack = 0;
  958.     maxstack = 0;
  959.  
  960.     /* first find out how many methods have been declared */
  961.     /* also check for multiply defined methods */
  962.     for (m = mlist, i = 0; m; i++, m = m->nextmethod)
  963.         for (n = m->nextmethod; n; n = n->nextmethod)
  964.             if (streq((m->pattern)->cmdname ,
  965.                 (n->pattern)->cmdname))
  966.                 yerr("%s multiply defined",
  967.                     (m->pattern)->cmdname);
  968.  
  969.     fprintf(ofd,"temp <- <primitive 110 %d >\n", i);
  970.  
  971.     /* next print out each method */
  972.     for (m = mlist, i = 1; m; i++, m = m->nextmethod) {
  973.         fprintf(ofd,"<primitive 112 temp %d\t\t\" %s \" \\\n",
  974.             i, (m->pattern)->cmdname);
  975.         topstack = 0;
  976.         genmeth(m);
  977.         }
  978.  
  979.     /* finally print out class definition stuff */
  980.     fprintf(ofd,"<primitive 98 #%s \\\n", clinfo->name);
  981.     fprintf(ofd,"\t<primitive 97 #%s #%s #%s \\\n",
  982.         clinfo->name, clinfo->super, filename);
  983.     fprintf(ofd,"\t#( ");
  984.     if (instvars) prvars(instvars);
  985.     fprintf(ofd," ) \\\n");
  986.     fprintf(ofd,"\t#( ");
  987.     for (m = mlist; m; m = m->nextmethod)
  988.         fprintf(ofd,"#%s ", (m->pattern)->cmdname);
  989.     fprintf(ofd," ) \\\n");
  990.     fprintf(ofd,"\ttemp %d %d > >\n\n", 1 + maxcontext, 1 + maxstack);
  991. }
  992.  
  993. prvars(v)
  994. struct varstruct *v;
  995. {
  996.     if (v->nextvar)
  997.         prvars(v->nextvar);
  998.     fprintf(ofd," #%s", v->text);
  999. }
  1000.  
  1001. static int codetop = 0;
  1002. static uchar code[1000];
  1003.  
  1004. static gencode(value)
  1005. int value;
  1006. {
  1007.    if (value >= 256) {
  1008.     yerr("code word too big: %d", value);
  1009.     }
  1010.    code[codetop++] = itouc(value);
  1011. }
  1012.  
  1013. static genhighlow(high, low)
  1014. int high, low;
  1015. {
  1016.    if (high < 0 || high > 16)
  1017.     yerr("genhighlow error: %d", high);
  1018.    if (low < 16) gencode(high * 16 + low);
  1019.    else {
  1020.       gencode(TWOBIT * 16 + high);
  1021.       gencode(low);
  1022.       }
  1023. }
  1024.  
  1025. static struct litstruct *literals[100];
  1026. int littop = 0;
  1027.  
  1028. int litcomp(l1, l2)
  1029. struct litstruct *l1, *l2;
  1030. {
  1031.    if (l1->littype != l2->littype) return(0);
  1032.    switch(l1->littype) {
  1033.       case charlit: if (l1->ll.litchar != l2->ll.litchar) return(0); break;
  1034.       case numlit: if (l1->ll.litint != l2->ll.litint) return(0); break;
  1035.       case fnumlit: if (l1->ll.litstr != l2->ll.litstr) return(0); break;
  1036.       case strlit:  if (strcmp(l1->ll.litstr, l2->ll.litstr)) return(0); break;
  1037.       case symlit:  if (strcmp(l1->ll.litsym, l2->ll.litsym)) return(0); break;
  1038.       default: return(0);
  1039.       }
  1040.    return(1);
  1041. }
  1042.  
  1043. int genlitix(l)
  1044. struct litstruct *l;
  1045. {    int i;
  1046.  
  1047.     for (i = 0; i < littop; i++)
  1048.         if (litcomp(l, literals[i]))
  1049.             return(i);
  1050.     i = littop;
  1051.     literals[littop++] = l;
  1052.     return(i);
  1053. }
  1054.  
  1055. static printalit(lit)
  1056. struct litlist *lit;
  1057. {
  1058.    if (lit) {
  1059.       if(lit->nextlit)
  1060.         printalit(lit->nextlit);
  1061.       printlit(lit->litele);
  1062.       }
  1063. }
  1064.  
  1065. printlit(lit)
  1066. struct litstruct *lit;
  1067. {
  1068.    if (lit)
  1069.       switch(lit->littype) {
  1070.          case numlit: fprintf(ofd,"%d ", lit->ll.litint); break;
  1071.          case fnumlit: fprintf(ofd,"%s ", lit->ll.litstr); break;
  1072.          case charlit: fprintf(ofd,"$%c ", lit->ll.litchar); break;
  1073.          case strlit:  fprintf(ofd,"\'%s\' ", lit->ll.litstr); break;
  1074.          case symlit:  fprintf(ofd,"#%s ", lit->ll.litsym); break;
  1075.          case arlit:   fprintf(ofd,"#( ");
  1076.                        printalit(lit->ll.litarry);
  1077.                        fprintf(ofd,") ");
  1078.                        break;
  1079.          default: yerr("unknown literal type %d", lit->littype);
  1080.          }
  1081. }
  1082.  
  1083. genmeth(m)
  1084. struct methodstruct *m;
  1085. {     int i;
  1086.  
  1087.     fprintf(ofd,"\t#( #[");
  1088.     codetop = littop = 0;
  1089.     genstate(m->states, 1);
  1090.     genhighlow(SPECIAL, SELFRETURN);
  1091.     for (i = 0; i < codetop; i++){
  1092.            fprintf(ofd," %d", uctoi(code[i]));
  1093.         if (i % 15 == 14) fprintf(ofd," \\\n");
  1094.         }
  1095.     fprintf(ofd,"] \\\n");
  1096.     fprintf(ofd,"\t#( ");
  1097.     for (i = 0; i < littop; i++)
  1098.         printlit(literals[i]);
  1099.     fprintf(ofd," ) ) >\n\n");
  1100. }
  1101.  
  1102. genstate(s, doret)
  1103. struct statestruct *s;
  1104. int doret;
  1105. {
  1106.     if (s->nextstate)
  1107.         genstate(s->nextstate, doret);
  1108.     switch(s->statetype) {
  1109.         default:
  1110.             yerr("unknown case in genstate %d", s->statetype);
  1111.         case blkupar:
  1112.             gensexpr(s->nn.stateexpr);
  1113.             if (inblock)
  1114.                 genhighlow(SPECIAL, BLOCKRETURN);
  1115.             else
  1116.                 genhighlow(SPECIAL, RETURN);
  1117.             popstk(1);
  1118.             break;
  1119.         case upar:
  1120.             gensexpr(s->nn.stateexpr);
  1121.             if (doret)
  1122.                 genhighlow(SPECIAL, RETURN);
  1123.             popstk(1);
  1124.             break;
  1125.         case iasgn:
  1126.             gensexpr(s->nn.stateexpr);
  1127.             genhighlow(POPINSTANCE, s->mm.varpos);
  1128.             popstk(1);
  1129.             break;
  1130.         case casgn:
  1131.             gensexpr(s->nn.stateexpr);
  1132.             genhighlow(POPTEMP, s->mm.varpos);
  1133.             popstk(1);
  1134.             break;
  1135.         case expr:
  1136.             genexpr(s->nn.cmd);
  1137.             genhighlow(SPECIAL, POPSTACK);
  1138.             popstk(1);
  1139.             break;
  1140.         }
  1141. }
  1142.  
  1143. gensexpr(s)
  1144. struct statestruct *s;
  1145. {
  1146.     switch(s->statetype) {
  1147.         default:
  1148.             yerr("unknown state in gensexpr %d", s->statetype);
  1149.         case iasgn:
  1150.             gensexpr(s->nn.stateexpr);
  1151.             genhighlow(SPECIAL, DUPSTACK);
  1152.             bumpstk();
  1153.             genhighlow(POPINSTANCE, s->mm.varpos);
  1154.             popstk(1);
  1155.             break;
  1156.         case casgn:
  1157.             gensexpr(s->nn.stateexpr);
  1158.             genhighlow(SPECIAL, DUPSTACK);
  1159.             bumpstk();
  1160.             genhighlow(POPTEMP, s->mm.varpos);
  1161.             popstk(1);
  1162.             break;
  1163.         case expr:
  1164.             genexpr(s->nn.cmd);
  1165.             break;
  1166.         }
  1167. }
  1168.  
  1169. int supertest(rec)
  1170. struct exprstruct *rec;
  1171. {    struct objstruct *o;
  1172.  
  1173.     if (rec->cmdtype != reccmd)
  1174.         return(0);
  1175.     o = rec->cc.recobj;
  1176.     if (o->objtype != pseuobj)
  1177.         return(0);
  1178.     if (o->ee.pseuinfo == supervar)
  1179.         return(1);
  1180.     return(0);
  1181. }
  1182.  
  1183. int isblock(e)
  1184. struct exprstruct *e;
  1185. {    struct objstruct *o;
  1186.  
  1187.     if (e->cmdtype != reccmd)
  1188.         return(0);
  1189.     o = e->cc.recobj;
  1190.     if (o->objtype != blockobj)
  1191.         return(0);
  1192.     return(1);
  1193. }
  1194.  
  1195. genbarg(e)
  1196. struct exprstruct *e;
  1197. {
  1198.     if (isblock(e)) {
  1199.         genstate(((e->cc.recobj)->ee.blockinfo)->bstates, 0);
  1200.         }
  1201.     else {
  1202.         genexpr(e);
  1203.         genhighlow(UNSEND, VALUECMD);
  1204.         }
  1205. }
  1206.  
  1207. fixjump(loc)
  1208. int loc;
  1209. {    int size;
  1210.     
  1211.     size = (codetop - loc) - 1;
  1212.     if (size > 255)
  1213.         yerr("block too big %d", size);
  1214.     code[loc] = itouc(size);
  1215. }
  1216.  
  1217. int gencond(message, e)
  1218. char *message;
  1219. struct exprstruct *e;
  1220. {    struct keylist *k;
  1221.     int i, j;
  1222.  
  1223.      k = e->cc.keys;
  1224.     i = 0;
  1225.     if ((i = streq(message, "ifTrue:")) || streq(message, "ifFalse:")) {
  1226.         genhighlow(SPECIAL, i ? SKIPFALSEPUSH : SKIPTRUEPUSH);
  1227.         i = codetop;
  1228.         gencode(0);
  1229.         genbarg(k->arg);
  1230.         fixjump(i);
  1231.         return(1);
  1232.         }
  1233.     if ((i = streq(message, "ifTrue:ifFalse:")) ||
  1234.             streq(message, "ifFalse:ifTrue:")) {
  1235.         genhighlow(SPECIAL, i ? SKIPFALSEPUSH : SKIPTRUEPUSH);
  1236.         i = codetop;
  1237.         gencode(0);
  1238.         genbarg((k->nextkey)->arg);
  1239.         genhighlow(SPECIAL, SKIPFORWARD);
  1240.         j = codetop;
  1241.         gencode(0);
  1242.         fixjump(i);
  1243.         genhighlow(SPECIAL, POPSTACK);
  1244.         popstk(1);
  1245.         genbarg(k->arg);
  1246.         fixjump(j);
  1247.         return(1);
  1248.         }
  1249.     if ((i = streq(message, "and:")) || streq(message, "or:")) {
  1250.         genhighlow(SPECIAL, i ? SKIPF : SKIPT);
  1251.         i = codetop;
  1252.         gencode(0);
  1253.         genbarg(k->arg);
  1254.         fixjump(i);
  1255.         return(1);
  1256.         }
  1257.     if ((j = streq(message, "whileTrue:")) ||
  1258.             streq(message, "whileFalse:")) {
  1259.         i = codetop;
  1260.         genbarg(e->receiver);
  1261.         genhighlow(SPECIAL, j ? SKIPFALSEPUSH : SKIPTRUEPUSH);
  1262.         j = codetop;
  1263.         gencode(0);
  1264.         genbarg(k->arg);
  1265.         genhighlow(SPECIAL, POPSTACK);
  1266.         popstk(1);
  1267.         genhighlow(SPECIAL, SKIPBACK);
  1268.         /* add one because bytecount pointer already advanced */
  1269.         gencode((codetop - i) + 1);
  1270.         fixjump(j);
  1271.         return(1);
  1272.         }
  1273.     return(0);
  1274. }
  1275.  
  1276. genexpr(e)
  1277. struct exprstruct *e;
  1278. {    char *message = e->cmdname;
  1279.     char **p;
  1280.     int  i, numargs, s;
  1281.     YYSTYPE ex;
  1282.     struct litstruct *mklit();
  1283.  
  1284.     if (e->cmdtype != reccmd)
  1285.         s = supertest(e->receiver);
  1286.     switch(e->cmdtype) {
  1287.         default:
  1288.             yerr("unknown state in genexpr %d", e->cmdtype);
  1289.         case reccmd:
  1290.             genobj(e->cc.recobj);
  1291.             return;
  1292.         case semiend:
  1293.             genexpr(e->receiver);
  1294.             genhighlow(SPECIAL, POPSTACK);
  1295.             popstk(1);
  1296.             return;
  1297.         case semistart:
  1298.             genexpr(e->receiver);
  1299.             genhighlow(SPECIAL, DUPSTACK);
  1300.             bumpstk();
  1301.             return;
  1302.         case uncmd:
  1303.             genexpr(e->receiver);
  1304.             numargs = 0;
  1305.             break;
  1306.         case bincmd:
  1307.             genexpr(e->receiver);
  1308.             numargs = 1;
  1309.             genexpr(e->cc.argument);
  1310.             break;
  1311.         case keycmd:
  1312.             if ((!s) && isblock(e->receiver) &&
  1313.                 (streq(message, "whileTrue:") ||
  1314.                  streq(message, "whileFalse:")))
  1315.                  if (gencond(message, e))
  1316.                     return;
  1317.             genexpr(e->receiver);
  1318.             if ((!s) && ((streq(message, "ifTrue:")) ||
  1319.                 (streq(message, "ifFalse:")) ||
  1320.                 (streq(message, "and:")) ||
  1321.                 (streq(message, "or:")) ||
  1322.                 (streq(message, "ifTrue:ifFalse:")) ||
  1323.                 (streq(message, "ifFalse:ifTrue:"))))
  1324.                 if (gencond(message, e))
  1325.                     return;
  1326.             numargs = genkargs(e->cc.keys);
  1327.             break;
  1328.         }
  1329.     if (s) {    /* message to super */
  1330.         genhighlow(SUPERSEND, numargs);
  1331.         popstk(numargs - 1);
  1332.         ex.c = message;
  1333.         gencode(genlitix(mklit(symlit, &ex)));
  1334.         return;
  1335.         }
  1336.     for (p = unspecial, i = 0; *p; i++, p++)
  1337.         if (strcmp(*p, message) == 0) {
  1338.             genhighlow(UNSEND, i);
  1339.             return;
  1340.             }
  1341.     for (p = binspecial, i = 0; *p; i++, p++)
  1342.         if (strcmp(*p, message) == 0) {
  1343.             genhighlow(BINSEND, i);
  1344.             popstk(1);
  1345.             return;
  1346.             }
  1347.     for (p = arithspecial, i = 0; *p; i++, p++)
  1348.         if (strcmp(*p, message) == 0) {
  1349.             genhighlow(ARITHSEND, i);
  1350.             popstk(1);
  1351.             return;
  1352.             }
  1353.     for (p = keyspecial, i = 0; *p; i++, p++)
  1354.         if (strcmp(*p, message) == 0) {
  1355.             genhighlow(KEYSEND, i);
  1356.             popstk(2);
  1357.             return;
  1358.             }
  1359.     genhighlow(SEND, numargs);
  1360.     popstk(numargs - 1);
  1361.     ex.c = message;
  1362.     gencode(genlitix(mklit(symlit, &ex)));
  1363. }
  1364.  
  1365. int genkargs(kl)
  1366. struct keylist *kl;
  1367. {    int i;
  1368.     
  1369.     if (kl->nextkey)
  1370.         i = genkargs(kl->nextkey);
  1371.     else i = 0;
  1372.     genexpr(kl->arg);
  1373.     return(i + 1);
  1374. }
  1375.  
  1376. genobj(o)
  1377. struct objstruct *o;
  1378. {
  1379.     switch(o->objtype) {
  1380.         default:
  1381.             yerr("unknown state in genobj %d", o->objtype);
  1382.         case classobj:
  1383.             genspclass(o->ee.litinfo);
  1384.             break;
  1385.         case instvarobj:
  1386.             genhighlow(PUSHINSTANCE, o->ee.varoffset);
  1387.             bumpstk();
  1388.             break;
  1389.         case contvarobj:
  1390.             genhighlow(PUSHTEMP, o->ee.varoffset);
  1391.             bumpstk();
  1392.             break;
  1393.         case litobj:
  1394.             genlit(o->ee.litinfo);
  1395.             break;
  1396.         case pseuobj:
  1397.             genpseu(o->ee.pseuinfo);
  1398.             break;
  1399.         case primobj:
  1400.             genprim(o->ee.priminfo);
  1401.             break;
  1402.         case exprobj:
  1403.             gensexpr(o->ee.stateinfo);
  1404.             break;
  1405.         case blockobj:
  1406.             genblock(o->ee.blockinfo);
  1407.             break;
  1408.         }
  1409. }
  1410.  
  1411. genspclass(litinfo)
  1412. struct litstruct *litinfo;
  1413. {    int i;
  1414.     char **p, *name;
  1415.  
  1416.     if (litinfo->littype != symlit)
  1417.         yerr("can't happen in genspclass %d", litinfo->littype);
  1418.     name = litinfo->ll.litsym;
  1419.     for (p = classpecial, i = 30; *p; i++, p++)
  1420.         if (strcmp(name, *p) == 0) {
  1421.             genhighlow(PUSHSPECIAL, i);
  1422.             bumpstk();
  1423.             return;
  1424.             }
  1425.     genhighlow(PUSHCLASS, genlitix(litinfo));
  1426.     bumpstk();
  1427. }
  1428.  
  1429. genpseu(p)
  1430. enum pseuvars p;
  1431. {
  1432.  
  1433.     switch(p) {
  1434.         default: yerr("unknown state in genpseu %d", p);
  1435.         case truevar:  genhighlow(PUSHSPECIAL, 11); break;
  1436.         case falsevar: genhighlow(PUSHSPECIAL, 12); break;
  1437.         case nilvar:   genhighlow(PUSHSPECIAL, 13); break;
  1438.         case smallvar: genhighlow(PUSHSPECIAL, 14); break;
  1439.         case procvar:  genhighlow(PUSHSPECIAL, 15); break;
  1440.         case supervar:
  1441.         case selfvar:  genhighlow(PUSHTEMP, 0); break;
  1442.         }
  1443.     bumpstk();
  1444. }
  1445.  
  1446. int genpargs(p)
  1447. struct primlist *p;
  1448. {    int i;
  1449.  
  1450.     if (p) {
  1451.         i = 1 + genpargs(p->nextprim);
  1452.         genobj(p->pobject);
  1453.         }
  1454.     else i = 0;
  1455.     return(i);
  1456. }
  1457.  
  1458. genprim(p)
  1459. struct primstruct *p;
  1460. {    int i;
  1461.  
  1462.     i = genpargs(p->plist);
  1463.     genhighlow(SPECIAL, PRIMCMD);
  1464.     popstk(i-1);
  1465.     gencode(i);
  1466.     /*genhighlow(9, i); TEST- DEBUG*/
  1467.     gencode(p->primnumber);
  1468. }
  1469.  
  1470. genlit(l)
  1471. struct litstruct *l;
  1472. {    int i;
  1473.  
  1474.     if (l->littype == numlit) {
  1475.         i = l->ll.litint;
  1476.         if (i == -1)
  1477.             genhighlow(PUSHSPECIAL, 10);
  1478.         else if (i >= 0 && i < 10)
  1479.             genhighlow(PUSHSPECIAL, i);
  1480.         else if ((i > 15) && (i < 30))
  1481.             genhighlow(PUSHSPECIAL, i);
  1482.         else if ((i > 60) && (i < 256))
  1483.             genhighlow(PUSHSPECIAL, i);
  1484.         else
  1485.             genhighlow(PUSHLIT, genlitix(l));
  1486.  
  1487.         }
  1488.     else
  1489.         genhighlow(PUSHLIT, genlitix(l));
  1490.     bumpstk();
  1491. }
  1492.  
  1493. genblock(b)
  1494. struct blockstruct *b;
  1495. {    int i, size, bsave;
  1496.  
  1497.     bsave = inblock;
  1498.     inblock |= 1;
  1499.     genhighlow(BLOCKCREATE, b->numargs);
  1500.     bumpstk();
  1501.     if (b->numargs)
  1502.         gencode(b->arglocation);
  1503.     i = codetop;
  1504.     gencode(0); /* block size */
  1505.     genstate(b->bstates, 1);
  1506.     size = (codetop - i) - 1;
  1507.     if (size > 255)
  1508.         yerr("block too big %d", size);
  1509.     code[i] = size;
  1510.     inblock = bsave;
  1511. }
  1512. End
  1513. echo unbundling disclaim 1>&2
  1514. cat >disclaim <<'End'
  1515. /*
  1516.     The source code for the Little Smalltalk System may be freely
  1517.     copied provided that the source of all files is acknowledged
  1518.     and that this condition is copied with each file.
  1519.  
  1520.     The Little Smalltalk System is distributed without responsibility
  1521.     for the performance of the program and without any guarantee of
  1522.     maintenance.
  1523.  
  1524.     All questions concerning Little Smalltalk should be addressed to:
  1525.  
  1526.         Professor Tim Budd
  1527.         Department of Computer Science
  1528.         Oregon State University
  1529.         Corvallis, Oregon
  1530.         97331
  1531.         USA
  1532. */
  1533. End
  1534. echo unbundling Makefile 1>&2
  1535. cat >Makefile <<'End'
  1536. CFLAGS =
  1537. LFLAGS =
  1538.  
  1539. BINDIR = ../bin
  1540.  
  1541. SOURCES = parser.y parser.lex parse1.c parse2.c
  1542. MISC = disclaim Makefile *.h y.tab.c lex.yy.c uchar.c
  1543.  
  1544. install: parse
  1545.     mv parse $(BINDIR)
  1546.  
  1547. parse: y.tab.o parse1.o parse2.o
  1548.     cc $(LFLAGS) -o parse y.tab.o parse1.o parse2.o -lm
  1549.  
  1550. newparse: y.tab.o parse1.o parse2.o
  1551.     cc $(LFLAGS) -o newparse y.tab.o parse1.o parse2.o -lm
  1552.  
  1553. bundle: y.tab.c lex.yy.c
  1554.     bundle $(SOURCES) $(MISC) >../parser.bundle
  1555.  
  1556. y.tab.o: y.tab.c lex.yy.c primnum.h
  1557.  
  1558. y.tab.c: parser.y
  1559.     yacc -d parser.y
  1560.  
  1561. lex.yy.c: parser.lex
  1562.     lex parser.lex
  1563.  
  1564. parse2.o: parse2.c drive.h
  1565.  
  1566. lint.out: y.tab.c
  1567.     lint y.tab.c parse1.c parse2.c -lm
  1568.  
  1569. clean:
  1570.     -rm *.o
  1571. End
  1572. echo unbundling cmds.h 1>&2
  1573. cat >cmds.h <<'End'
  1574. /*
  1575.     Little Smalltalk
  1576.  
  1577.     The following very common commands are given a concise description
  1578.     in bytecodes.
  1579.  
  1580. */
  1581.  
  1582. static char *unspecial[] = {"new", "isNil", "notNil", "size", "class",
  1583.         "value", "first", "next", "print", "printString",
  1584.         "strictlyPositive", "currentKey", "not",
  1585.  
  1586.         /* after the first 16 - which should be the most common
  1587.         messages, order doesn't make as much difference so we
  1588.         might as well list things in alphabetical order */
  1589.  
  1590.         "abs",
  1591.         "asArray",
  1592.         "asFloat",
  1593.         "asString",
  1594.         "asSymbol",
  1595.         "block",
  1596.         "compareError",
  1597.         "copy",
  1598.         "current",
  1599.         "deepCopy",
  1600.         "exp",
  1601.         "findLast",
  1602.         "firstKey",
  1603.         "gamma",
  1604.         "isEmpty",
  1605.         "isLowercase",
  1606.         "isUppercase",
  1607.         "last",
  1608.         "lastKey",
  1609.         "ln",
  1610.         "newProcess",
  1611.         "not",
  1612.         "opError",
  1613.         "read",
  1614.         "removeError",
  1615.         "removeFirst",
  1616.         "removeLast",
  1617.         "resume",
  1618.         "rounded",
  1619.         "shallowCopy",
  1620.         "sqrt",
  1621.         "squared",
  1622.         "state",
  1623.         "superClass",
  1624.         "truncated",
  1625.         "unblock",
  1626.         "x",
  1627.         "y",
  1628.         0 };
  1629.  
  1630. # define VALUECMD 5
  1631. # define PRNTCMD  8
  1632.  
  1633. static char *binspecial[] = {"new:", "at:", "to:", "do:", "value:",
  1634.                       "==", "~~", "timesRepeat:", "whileTrue:", "whileFalse:",
  1635.                       "ifTrue:", "ifFalse:", "error:", "add:",
  1636.               "/", "coerce:",
  1637.  
  1638.               "^",
  1639.               ",",
  1640.               "//",
  1641.               "addAll:",
  1642.               "addAllLast:",
  1643.               "addFirst:",
  1644.               "addLast:",
  1645.               "binaryDo:",
  1646.               "checkBucket:",
  1647.               "collect:",
  1648.               "deepCopy:",
  1649.               "gcd:",
  1650.               "getList:",
  1651.               "hashNumber:",
  1652.               "includes:",
  1653.               "inRange:",
  1654.               "keysDo:",
  1655.               "log:",
  1656.               "maxtype:",
  1657.               "newProcessWith:",
  1658.               "occurrencesOf:",
  1659.               "raisedTo:",
  1660.               "reject:",
  1661.               "remove:",
  1662.               "removeKey:",
  1663.               "respondsTo:",
  1664.               "reverseDo:",
  1665.               "roundTo:",
  1666.               "select:",
  1667.               "shallowCopy:",
  1668.               "sort:",
  1669.               "termErr:",
  1670.               "truncateTo:",
  1671.               "write:",
  1672.               "x:",
  1673.               "y:",
  1674.               "includesKey:",
  1675.               0};
  1676.  
  1677. static char *arithspecial[] = {"+", "-", "*", "\\\\",
  1678.                         "bitShift:", "bitAnd:", "bitOr:",
  1679.                         "<", "<=", "=", "~=", ">=", ">",
  1680.             "rem:", "quo:", "min:", "max:",
  1681.             0};
  1682.  
  1683. static char *keyspecial[] = {"at:put:", "ifTrue:ifFalse:", "ifFalse:ifTrue:",
  1684.                         "value:value:", "to:by:", "at:ifAbsent:",
  1685.             "indexOf:ifAbsent:", "inject:into:",
  1686.             "remove:ifAbsent:", "removeKey:ifAbsent:",
  1687.             "between:and:",
  1688.             "findFirst:ifAbsent:", "findLast:ifAbsent:",
  1689.             "equals:startingAt:",
  1690.             "findAssociation:inList:",
  1691.             "detect:ifAbsent:",
  1692.             0};
  1693.  
  1694. /*    The classes included in the standard prelude
  1695.     also have a very concise description in bytecode representation
  1696. */
  1697.  
  1698. static char *classpecial[] = {"Array", "ArrayedCollection",
  1699.     "Bag", "Block", "Boolean", "ByteArray",
  1700.     "Char", "Class", "Collection", "Complex",
  1701.     "Dictionary", "False", "File", "Float",
  1702.     "Integer", "Interpreter", "Interval",
  1703.     "KeyedCollection", "List", "Magnitude", "Number",
  1704.     "Object", "OrderedCollection", "Point",
  1705.     "Radian", "Random",
  1706.     "SequenceableCollection", "Set", "String", "Symbol",
  1707.     "True", "UndefinedObject",
  1708.     0 };
  1709. End
  1710. echo unbundling drive.h 1>&2
  1711. cat >drive.h <<'End'
  1712. /*
  1713.     Little Smalltalk
  1714.  
  1715.         defines used by both parser and driver
  1716.  
  1717. */
  1718.  
  1719. # define TWOBIT         0
  1720. # define PUSHINSTANCE   1
  1721. # define PUSHTEMP       2
  1722. # define PUSHLIT        3
  1723. # define PUSHCLASS      4
  1724. # define PUSHSPECIAL    5
  1725. # define POPINSTANCE    6
  1726. # define POPTEMP        7
  1727. # define SEND           8
  1728. # define SUPERSEND      9
  1729. # define UNSEND        10
  1730. # define BINSEND       11
  1731. # define ARITHSEND     12
  1732. # define KEYSEND       13
  1733. # define BLOCKCREATE   14
  1734. # define SPECIAL       15
  1735.  
  1736. /* arguments for special */
  1737.  
  1738. # define NOOP           0
  1739. # define DUPSTACK       1
  1740. # define POPSTACK       2
  1741. # define RETURN         3
  1742. # define BLOCKRETURN    4
  1743. # define SELFRETURN     5
  1744. # define SKIPTRUEPUSH   6
  1745. # define SKIPFALSEPUSH  7
  1746. # define SKIPFORWARD    8
  1747. # define SKIPBACK       9
  1748. # define PRIMCMD       10
  1749. # define SKIPT         11
  1750. # define SKIPF         12
  1751.  
  1752. enum pseuvars {nilvar, truevar, falsevar, selfvar, supervar, smallvar,
  1753.         procvar};
  1754.  
  1755. # define streq(a,b) (strcmp(a,b) == 0)
  1756.  
  1757. /* only include driver code in driver, keeps both lint and the 11/70 quiet */
  1758. # ifdef DRIVECODE
  1759.  
  1760.  enum lextokens { nothing, LITNUM , LITFNUM , LITCHAR , LITSTR , LITSYM ,
  1761.     LITARR , LITBYTE , ASSIGN , BINARY , PRIMITIVE , PSEUDO ,
  1762.     UPPERCASEVAR , LOWERCASEVAR , COLONVAR , KEYWORD ,
  1763.      LP , RP , LB , RB , PERIOD , BAR , SEMI , PS , MINUS , PE , NL };
  1764.  
  1765. typedef union  {
  1766.     char         *c;
  1767.     double          f;
  1768.     int           i;
  1769.     enum pseuvars      p;
  1770.     } tok_type;
  1771.  
  1772. extern tok_type t;
  1773.  
  1774. # endif
  1775. End
  1776. echo unbundling env.h 1>&2
  1777. cat >env.h <<'End'
  1778. /*
  1779.     Little Smalltalk
  1780.  
  1781.     execution environment definitions.
  1782.  
  1783. The Little Smalltalk system is tailored to various machines by
  1784. changing defined constants.  These constants, and their meanings,
  1785. are as follows:
  1786.  
  1787. CURSES    defined if the curses(3) library is available and the primitive
  1788.     graphics it provides is desired
  1789.  
  1790. GAMMA    defined if gamma() is part of the math library
  1791.  
  1792. ENVSAVE    defined if it is required to save environ during fast load
  1793.  
  1794. FACTMAX    maximum integer value for which a factorial can be computed by
  1795.     repeated multiplication without overflow.
  1796.  
  1797. FASTDEFAULT    defined if the default behavior should be to do a fast load
  1798.  
  1799. FLUSHREQ    if defined a fflush is given after every call to printf
  1800.         or fprintf
  1801.  
  1802. INLINE    generate inline code for increments or decrements -
  1803.     produces larger, but faster, code.
  1804.  
  1805. MDWINDOWS    defined if the maryland windows package is used
  1806.  
  1807. NOSYSTEM    defined if the system() call is NOT provided
  1808.         (seriously limits functionality)
  1809.  
  1810. OPEN3ARG    defined if 3 argument style opens are used
  1811.  
  1812. PLOT3    defined if you have a device for which the plot(3) routines work
  1813.     directly on the terminal (without a filter)
  1814.     provides many of these routines as primitive operations
  1815.     (see class PEN in /prelude)
  1816.  
  1817. SMALLDATA    if defined various means are used to reduce the size of the
  1818.         data segment, at the expense of some functionality.
  1819.  
  1820. SIGS        define in the signal system call is available
  1821.         for trapping user interrupt signals
  1822.  
  1823. SETJUMP        defined if the setjump facility is available
  1824.  
  1825.     In addition to defining constants, the identifier type ``unsigned
  1826. character'' needs to be defined.  Bytecodes are stored using this datatype.
  1827. On machines which do not support this datatype directly, macros need to be
  1828. defined that convert normal chars into unsigned chars.  unsigned chars are
  1829. defined by a typedef for ``uchar'' and a pair of macros that convert an int
  1830. into a uchar and vice-versa.
  1831.  
  1832.     In order to simplify installation on systems to which the
  1833. Little Smalltalk system has already been ported, various ``meta-defines''
  1834. are recognized.  By defining one of these symbols, the correct definitions
  1835. for other symbols will automatically be generated.  The currently
  1836. recognized meta-defines are as follows:
  1837.     
  1838. BERK42    Vax Berkeley 4.2
  1839. DECPRO    Dec Professional 350 running Venix
  1840. HP9000    Hewlett Packard 9000
  1841. PDP1170    PdP 11/70 (also other PDP 11 machines)
  1842. PERKELM    Perken Elmer 8/32
  1843. RIDGE    Ridge ROS 3.1
  1844.  
  1845.     Finally, a few path names have to be compiled into the code.
  1846. These path names are the following:
  1847.  
  1848. TEMPFILE - a temporary file name in mktemp format
  1849. PARSER - the location of the parser
  1850. PRELUDE - the location of the standard prelude in ascii format
  1851. FAST - the location of the standard prelude in saved format
  1852. LIBLOC - the location of the directory for additional libraries
  1853.  
  1854. */
  1855.  
  1856. # define TEMPFILE "/usr/tmp/stXXXXXX"
  1857. # define PARSER   "/users/budd/Projects/smalltalk/bin/parse"
  1858. # define PRELUDE  "/users/budd/Projects/smalltalk/prelude/standard"
  1859. # define FAST     "/users/budd/Projects/smalltalk/prelude/stdsave"
  1860. # define LIBLOC      "/users/budd/Projects/smalltalk/prelude"
  1861.  
  1862. /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>meta-define <<<<<<<<<<<<<<<*/
  1863.  
  1864. # define BERK42
  1865.  
  1866. /*------------------------------  VAX Berkeley 4.2 definition */
  1867. # ifdef BERK42
  1868.  
  1869. # define GAMMA        /* gamma value is known */
  1870. # define FACTMAX 12
  1871. # define FLUSHREQ    /* flush after every printf */
  1872. # define SIGS
  1873. # define SETJUMP
  1874. typedef unsigned char uchar;
  1875. # define itouc(x) ((uchar) x)
  1876. # define uctoi(x) ((int) x)
  1877. /* # define MDWINDOWS */
  1878. /* FASTLOADING DOES work, and should eventually be defined to be standard*/
  1879. /*# define FASTDEFAULT*/    /* default to fast-loading */
  1880.  
  1881. # endif        /* BERK42 definition */
  1882.  
  1883. /*------------------------------  HP 9000 / HP - UX definition */
  1884. # ifdef HP9000
  1885.  
  1886. # define GAMMA        /* gamma value is known */
  1887. # define FACTMAX 12
  1888. # define FLUSHREQ    /* flush after every printf */
  1889. # define SIGS
  1890. # define SETJUMP
  1891. typedef unsigned char uchar;
  1892. # define itouc(x) ((uchar) x)
  1893. # define uctoi(x) ((int) x)
  1894.  
  1895. # endif        /* HP 9000 definition */
  1896.  
  1897. /* ---------------------------------------RIDGE ROS 3.1 definition */
  1898. # ifdef RIDGE
  1899.  
  1900. # define GAMMA        /* gamma value is known */
  1901. # define FACTMAX 12
  1902. typedef unsigned char uchar;
  1903. # define itouc(x) ((uchar) x)
  1904. # define uctoi(x) ((int) x)
  1905.  
  1906. # endif        /* RIDGE definition */
  1907.  
  1908. /* --------------------------------------------DEC PRO definitions */
  1909. # ifdef DECPRO
  1910.  
  1911. /* GAMMA, OPEN3ARG not defined */
  1912. # define ENVSAVE
  1913. # define FACTMAX 8
  1914. # define SMALLDATA
  1915. /* unsigned characters not supported, but can be simulated */
  1916. typedef char uchar;
  1917. # define itouc(x) ((uchar) x)
  1918. # define uctoi(x) (unsigned) (x >= 0 ? x : x + 256)
  1919.  
  1920. # endif        /* DECPRO definition */
  1921.  
  1922. /* --------------------------------------------PDP11/70 definitions */
  1923. # ifdef PDP1170
  1924.  
  1925. /* GAMMA, OPEN3ARG not defined */
  1926. # define ENVSAVE
  1927. # define FACTMAX 8
  1928. # define FLUSHREQ
  1929. # define SIGS
  1930. # define SETJUMP
  1931. /* unsigned characters not supported, but can be simulated */
  1932. typedef char uchar;
  1933. # define itouc(x) ((uchar) x)
  1934. # define uctoi(x) (unsigned) (x >= 0 ? x : x + 256)
  1935.  
  1936. # endif        /* PDP1170 definition */
  1937.  
  1938. /*------------------------------  Perkin Elmer 8/32 definitions */
  1939. # ifdef PERKELM
  1940.  
  1941. # define ENVSAVE
  1942. # define FACTMAX 12
  1943. # define FLUSHREQ    /* flush after every printf */
  1944. typedef unsigned char uchar;
  1945. # define itouc(x) ((uchar) x)
  1946. # define uctoi(x) ((int) x)
  1947.  
  1948. # endif        /* PERKELM definition */
  1949.  
  1950. /******************************************************************/
  1951. /*
  1952.     the following are pretty much independent of any system
  1953. */
  1954.  
  1955. # define INLINE        /* produce in line code for incs and decs */
  1956. /* # define CURSES    */
  1957. /* # define PLOT3     */
  1958. End
  1959. echo unbundling parser.h 1>&2
  1960. cat >parser.h <<'End'
  1961. /*
  1962.     Little Smalltalk
  1963.         definitions used by parser
  1964. */
  1965.  
  1966.  
  1967. enum vartypes {instvar, argvar, tempvar};
  1968.  
  1969. struct varstruct {
  1970.         struct varstruct *nextvar;
  1971.         enum vartypes vtype;
  1972.         char *text;
  1973.         short position;
  1974.         };
  1975.  
  1976. enum objtypes {classobj, varobj, instvarobj, contvarobj,
  1977.     litobj, pseuobj, primobj, exprobj, blockobj};
  1978.  
  1979. struct objstruct {
  1980.         enum objtypes objtype;
  1981.         union {
  1982.         char *varname;
  1983.         int varoffset;
  1984.                 struct litstruct *litinfo;
  1985.                 enum   pseuvars pseuinfo;
  1986.         struct primstruct *priminfo;
  1987.                 struct statestruct *stateinfo;
  1988.                 struct blockstruct *blockinfo;
  1989.              } ee;
  1990.         };
  1991.  
  1992. struct blockstruct {
  1993.     int arglocation;
  1994.     int numargs;
  1995.     struct statestruct *bstates;
  1996.     };
  1997.  
  1998. enum littypes {numlit, fnumlit, charlit, strlit, symlit, arlit, bytelit};
  1999.  
  2000. struct litstruct {
  2001.         enum littypes littype;
  2002.         union {
  2003.                 int litint;
  2004.                 char litchar;
  2005.                 char *litstr;
  2006.                 char *litsym;
  2007.                 struct litlist *litarry;
  2008.              } ll;
  2009.         };
  2010.  
  2011. struct litlist {
  2012.         struct litstruct *litele;
  2013.         struct litlist *nextlit;
  2014.         int    litposition;
  2015.         };
  2016.  
  2017. struct primstruct {
  2018.     int primnumber;
  2019.     struct primlist *plist;
  2020.     } ;
  2021.  
  2022. struct primlist {
  2023.     struct primlist *nextprim;
  2024.     struct objstruct *pobject;
  2025.     };
  2026.  
  2027. enum cmdtypes {reccmd, uncmd, bincmd, keycmd, semistart, semiend};
  2028.  
  2029. struct exprstruct {
  2030.         enum   cmdtypes cmdtype;
  2031.         char   *cmdname;
  2032.         struct exprstruct *receiver;
  2033.         union {
  2034.                 struct exprstruct *argument;
  2035.                 struct keylist *keys;
  2036.                 struct objstruct *recobj;
  2037.               } cc;
  2038.         struct exprstruct *nextcmd;
  2039.         };
  2040.  
  2041. enum statetypes {blkupar, upar, asgn, iasgn, casgn, expr};
  2042.  
  2043. struct statestruct {
  2044.         enum statetypes statetype;
  2045.         struct statestruct *nextstate;
  2046.         union {
  2047.                 struct varstruct *variable;
  2048.         int varpos;
  2049.               } mm;
  2050.         union {
  2051.                 struct statestruct *stateexpr;
  2052.                 struct exprstruct *cmd;
  2053.               } nn;
  2054.         };
  2055.  
  2056. struct keylist {
  2057.         char   *keyword;
  2058.         struct exprstruct *arg;
  2059.         struct keylist *nextkey;
  2060.         };
  2061.  
  2062. struct methodstruct {
  2063.     struct exprstruct *pattern;
  2064.     int    numtempvars;
  2065.         struct statestruct *states;
  2066.         struct methodstruct *nextmethod;
  2067.         };
  2068.  
  2069. struct classstruct {
  2070.         char *name;
  2071.         char *super;
  2072.         };
  2073.  
  2074. # define structalloc(type) (struct type *) alloc(sizeof (struct type ))
  2075.  
  2076. extern struct varstruct *instvars;
  2077. extern struct varstruct *contextvars;
  2078.  
  2079. # define addinst(x) (instvars = addvlist(mkvar(x, instvar), instvars))
  2080.  
  2081. extern char *walloc();
  2082. End
  2083. echo unbundling primnum.h 1>&2
  2084. cat >primnum.h <<'End'
  2085. /*
  2086.     Little Smalltalk
  2087.  
  2088.     primitive names and numbers recognized by the parser
  2089.  
  2090. */
  2091.  
  2092. static struct prim_names {
  2093.     char *p_name;
  2094.     int p_number;
  2095.     } prim_table[] = {
  2096.  
  2097.     /* Operations on all objects */
  2098. { "Class" , 1 },
  2099. { "SuperObject", 2 },
  2100. { "RespondsToNew", 3 },
  2101. { "Size", 4 },
  2102. { "HashNumber", 5},
  2103. { "SameTypeOfObject", 6},
  2104. { "Equality", 7},
  2105. { "Debug", 8},
  2106. { "GeneralityTest", 9},
  2107.     /* Integer Arithmetic Operations */
  2108. { "IntegerAddition" , 10 },
  2109. { "IntegerSubtraction", 11 },
  2110. { "IntegerLessThan", 12 },
  2111. { "IntegerGreaterThan", 13 },
  2112. { "IntegerLessThanOrEqual", 14 },
  2113. { "IntegerGreaterThanOrEqual", 15 },
  2114. { "IntegerEquality", 16 },
  2115. { "IntegerNonEquality", 17 },
  2116. { "IntegerMultiplication", 18 },
  2117. { "IntegerSlash", 19 },
  2118. { "GCD", 20 },
  2119. { "BitAt", 21 },
  2120. { "BitOR", 22 },
  2121. { "BitAND", 23 },
  2122. { "BitXOR", 24 },
  2123. { "BitShift", 25 },
  2124. { "RadixPrint", 26 },
  2125. { "IntegerDivision", 28 },
  2126. { "IntegerMod", 29 },
  2127. { "DoPrimitive", 30 },
  2128. { "RandomFloat", 32 },
  2129. { "BitInverse", 33 },
  2130. { "HighBit", 34 },
  2131. { "Random", 35 },
  2132. { "IntegerToCharacter", 36 },
  2133. { "IntegerToString", 37 },
  2134. { "Factorial", 38 },
  2135. { "IntegerToFloat", 39 },
  2136.     /* Character Operations */
  2137. { "CharacterLessThan", 42 },
  2138. { "CharacterGreaterThan", 43 },
  2139. { "CharacterLessThanOrEqual", 44 },
  2140. { "CharacterGreaterThanOrEqual", 45 },
  2141. { "CharacterEquality", 46 },
  2142. { "CharacterNonEquality", 47 },
  2143. { "DigitValue", 50 },
  2144. { "IsVowel", 51 },
  2145. { "IsAlpha", 52 },
  2146. { "IsLower", 53 },
  2147. { "IsUpper", 54 },
  2148. { "IsSpace", 55 },
  2149. { "IsAlnum", 56 },
  2150. { "ChangeCase", 57 },
  2151. { "CharacterToString", 58 },
  2152. { "CharacterToInteger", 59 },
  2153.     /* floating point operations */
  2154. { "FloatAddition", 60 },
  2155. { "FloatSubtraction", 61 },
  2156. { "FloatLessThan", 62 },
  2157. { "FloatGreaterThan", 63 },
  2158. { "FloatLessThanOrEqual", 64 },
  2159. { "FloatGreaterThanOrEqual", 65 },
  2160. { "FloatEquality", 66 },
  2161. { "FloatNonEquality", 67 },
  2162. { "FloatMultiplication", 68 },
  2163. { "FloatDivision", 69 },
  2164. { "Log", 70 },
  2165. { "SquareRoot", 71 },
  2166. { "Floor", 72 },
  2167. { "Ceiling", 73 },
  2168. { "IntegerPart", 75 },
  2169. { "FractionalPart", 76 },
  2170. { "Gamma", 77 },
  2171. { "FloatToString", 78},
  2172. { "Exponent", 79},
  2173. { "NormalizeRadian", 80},
  2174. { "Sin", 81},
  2175. { "Cos", 82},
  2176. { "ArcSin", 84},
  2177. { "ArcCos", 85},
  2178. { "ArcTan", 86},
  2179. { "Power", 88},
  2180. { "FloatRadixPrint", 89},
  2181.     /* symbol operations */
  2182. { "SymbolCompare", 91},
  2183. { "SymbolPrintString", 92},
  2184. { "SymbolAsString", 93},
  2185. { "SymbolPrint", 94},
  2186. { "NewClass", 97 },
  2187. { "InstallClass", 98},
  2188. { "FindClass", 99},
  2189.     /* string operations */
  2190. { "StringLength", 100},
  2191. { "StringCompare", 101},
  2192. { "StringCompareWithoutCase", 102},
  2193. { "StringCatenation", 103},
  2194. { "StringAt", 104},
  2195. { "StringAtPut", 105},
  2196. { "CopyFromLength", 106},
  2197. { "StringCopy", 107},
  2198. { "StringAsSymbol", 108},
  2199. { "StringPrintString", 109},
  2200.     /* arrays and other objects */
  2201. { "NewObject", 110},
  2202. { "At", 111},
  2203. { "AtPut", 112},
  2204. { "Grow", 113},
  2205. { "NewArray", 114},
  2206. { "NewString", 115},
  2207. { "NewByteArray", 116},
  2208. { "ByteArraySize", 117},
  2209. { "ByteArrayAt", 118},
  2210. { "ByteArrayAtPut", 119},
  2211.     /* I/O operations */
  2212. { "PrintNoReturn", 120},
  2213. { "PrintWithReturn", 121},
  2214. { "Error", 122},
  2215. { "ErrorPrint", 123},
  2216. { "System", 125},
  2217. { "PrintAt", 126},
  2218. { "BlockReturn", 127},
  2219. { "ReferenceError", 128},
  2220. { "DoesNotRespond", 129},
  2221.     /* operations on files */
  2222. { "FileOpen", 130},
  2223. { "FileRead", 131},
  2224. { "FileWrite", 132},
  2225. { "FileSetMode", 133},
  2226. { "FileSize", 134},
  2227. { "FileSetPosition", 135},
  2228. { "FileFindPosition", 136},
  2229.     /* Process management */
  2230. { "BlockExecute", 140},
  2231. { "NewProcess", 141},
  2232. { "Terminate", 142},
  2233. { "Perform", 143},
  2234. { "SetProcessState", 145},
  2235. { "ReturnProcessState", 146},
  2236. { "StartAtomic", 148},
  2237. { "EndAtomic", 149},
  2238.     /* operations on classes */
  2239. { "ClassEdit", 150},
  2240. { "SuperClass", 151},
  2241. { "ClassName", 152},
  2242. { "ClassNew", 153},
  2243. { "PrintMessages", 154},
  2244. { "RespondsTo", 155},
  2245. { "ClassView", 156},
  2246. { "ClassList", 157},
  2247. { "Variables", 158},
  2248.     /* misc operations */
  2249. { "CurrentTime", 160},
  2250. { "TimeCounter", 161},
  2251. { "Clear", 162},
  2252. { "GetString", 163},
  2253. { "StringAsInteger", 164},
  2254. { "StringAsFloat", 165},
  2255.     /* that's all */
  2256. { 0 , 0 } };
  2257.  
  2258. End
  2259. echo unbundling y.tab.h 1>&2
  2260. cat >y.tab.h <<'End'
  2261. # define LITNUM 257
  2262. # define LITFNUM 258
  2263. # define LITCHAR 259
  2264. # define LITSTR 260
  2265. # define LITSYM 261
  2266. # define CLASS 262
  2267. # define ASSIGN 263
  2268. # define BINARY 264
  2269. # define PRIMITIVE 265
  2270. # define NAMEDPRIM 266
  2271. # define PSEUDO 267
  2272. # define UPPERCASEVAR 268
  2273. # define LOWERCASEVAR 269
  2274. # define COLONVAR 270
  2275. # define KEYWORD 271
  2276. # define LP 272
  2277. # define RP 273
  2278. # define LB 274
  2279. # define RB 275
  2280. # define PERIOD 276
  2281. # define BAR 277
  2282. # define MBAR 278
  2283. # define SEMI 279
  2284. # define UPARROW 280
  2285. # define PS 281
  2286. # define MINUS 282
  2287. # define PE 283
  2288.  
  2289. typedef union  {
  2290.     struct litlist         *a;
  2291.     struct blockstruct     *b;
  2292.     char             *c;
  2293.     struct exprstruct     *e;
  2294.     int               i;
  2295.     struct keylist         *k;
  2296.     struct classstruct     *l;
  2297.     struct methodstruct     *m;
  2298.     struct objstruct     *o;
  2299.     enum pseuvars          p;
  2300.     struct primlist     *r;
  2301.     struct statestruct     *s;
  2302.     struct litstruct     *t;
  2303.     struct primstruct     *u
  2304.     } YYSTYPE;
  2305. extern YYSTYPE yylval;
  2306. End
  2307. echo unbundling y.tab.c 1>&2
  2308. cat >y.tab.c <<'End'
  2309. # define LITNUM 257
  2310. # define LITFNUM 258
  2311. # define LITCHAR 259
  2312. # define LITSTR 260
  2313. # define LITSYM 261
  2314. # define CLASS 262
  2315. # define ASSIGN 263
  2316. # define BINARY 264
  2317. # define PRIMITIVE 265
  2318. # define NAMEDPRIM 266
  2319. # define PSEUDO 267
  2320. # define UPPERCASEVAR 268
  2321. # define LOWERCASEVAR 269
  2322. # define COLONVAR 270
  2323. # define KEYWORD 271
  2324. # define LP 272
  2325. # define RP 273
  2326. # define LB 274
  2327. # define RB 275
  2328. # define PERIOD 276
  2329. # define BAR 277
  2330. # define MBAR 278
  2331. # define SEMI 279
  2332. # define UPARROW 280
  2333. # define PS 281
  2334. # define MINUS 282
  2335. # define PE 283
  2336.  
  2337. # line 26 "parser.y"
  2338. # include "env.h"
  2339. # include "drive.h"
  2340. # include "parser.h"
  2341.  
  2342. # line 31 "parser.y"
  2343. typedef union  {
  2344.     struct litlist         *a;
  2345.     struct blockstruct     *b;
  2346.     char             *c;
  2347.     struct exprstruct     *e;
  2348.     int               i;
  2349.     struct keylist         *k;
  2350.     struct classstruct     *l;
  2351.     struct methodstruct     *m;
  2352.     struct objstruct     *o;
  2353.     enum pseuvars          p;
  2354.     struct primlist     *r;
  2355.     struct statestruct     *s;
  2356.     struct litstruct     *t;
  2357.     struct primstruct     *u
  2358.     } YYSTYPE;
  2359.  
  2360. # line 49 "parser.y"
  2361. extern struct blockstruct *mkblock();
  2362. extern struct classstruct *mkclass();
  2363. extern struct varstruct *mkvar(), *addvlist(), *invlist();
  2364. extern struct methodstruct *mkmethod();
  2365. extern struct exprstruct *mkexpr(), *mkkey();
  2366. extern struct keylist *mkklist();
  2367. extern struct statestruct *mkstate();
  2368. extern struct objstruct *mkobj();
  2369. extern struct primstruct *mkprim();
  2370. extern struct primlist *addprim();
  2371. extern struct litstruct *mklit();
  2372. extern struct litlist *addlit();
  2373. extern char   *bincat();
  2374.  
  2375. struct varstruct *instvars;
  2376. struct varstruct *contextvars;
  2377.  
  2378. int bytetop = 0;
  2379. uchar bytearray[1000];
  2380.  
  2381. YYSTYPE e;
  2382. int errorcount = 0;
  2383. #define yyclearin yychar = -1
  2384. #define yyerrok yyerrflag = 0
  2385. extern int yychar;
  2386. extern short yyerrflag;
  2387. #ifndef YYMAXDEPTH
  2388. #define YYMAXDEPTH 150
  2389. #endif
  2390. YYSTYPE yylval, yyval;
  2391. # define YYERRCODE 256
  2392.  
  2393. # line 350 "parser.y"
  2394.  
  2395. # include <stdio.h>
  2396.  
  2397. char *filename;
  2398. FILE *fp;
  2399. FILE *ofd;
  2400.  
  2401. # include "lex.yy.c"
  2402.  
  2403. main(argc, argv)
  2404. int argc;
  2405. char **argv;
  2406. {    
  2407.     if (argc != 2) quiter("parser: wrong number of arguments");
  2408.     filename = argv[1];
  2409.     fp = fopen(filename, "r");
  2410.     if (fp == NULL) {
  2411.         yerr("cannot open input file %s", filename);
  2412.         quiter("parser quits");
  2413.         }
  2414.     ofd = stdout;
  2415.     return(yyparse());
  2416. }
  2417.  
  2418. quiter(s) char *s; {fprintf(stderr,"%s\n", s); exit(1);}
  2419.  
  2420. yywarn(s, v) char *s, *v; {
  2421.    fprintf(stderr, "%s: line %d: Warning ", filename, linenum);
  2422.    fprintf(stderr, s, v);
  2423.    fprintf(stderr,"\n");
  2424. }
  2425.  
  2426. yyerror(s) char *s; {yerr(s, "");}
  2427.  
  2428. yerr(s, v)
  2429. char *s, *v;
  2430. {
  2431.    fprintf(stderr, "%s: line %d: ", filename, linenum);
  2432.    fprintf(stderr, s, v);
  2433.    fprintf(stderr,"\n");
  2434.    if (errorcount++ > 10) quiter("too many errors, goodby");
  2435. }
  2436.  
  2437. expect(str) char *str;
  2438. {  char buffer[100];
  2439.  
  2440.    sprintf(buffer,"Expected %%s found %s", yytext);
  2441.    yerr(buffer, str);
  2442. }
  2443.  
  2444. int yywrap() { return(1);}
  2445.  
  2446. char *alloc(size) int size;      /* allocate a block of storage */
  2447. {  char *p, *malloc();
  2448.  
  2449.    p = malloc( (unsigned) size);
  2450.    if (p == (char *) 0) yyerror("out of free space");
  2451.    return(p);
  2452. }
  2453.  
  2454. char *bincat(s1, s2)
  2455. char *s1, *s2;
  2456. {    char *p;
  2457.  
  2458.     p = alloc(strlen(s1) + strlen(s2) + 1);
  2459.     strcpy(p, s1);
  2460.     strcat(p, s2);
  2461.     return(p);
  2462. }
  2463. short yyexca[] ={
  2464. -1, 1,
  2465.     0, -1,
  2466.     -2, 0,
  2467.     };
  2468. # define YYNPROD 120
  2469. # define YYLAST 370
  2470. short yyact[]={
  2471.  
  2472.   82,  80,  76,  77,  78, 129,  93,  25, 160, 155,
  2473.  145, 126, 125, 128, 127, 133, 159, 144, 158,  36,
  2474.   26,  90,  37,  28, 132, 134,  29,  82,  80,  76,
  2475.   77,  78, 129, 152,  25, 150, 157, 109, 126, 125,
  2476.  128, 127, 133, 122, 121, 116,  34,  26,  40, 107,
  2477.   28, 132, 134,  29,  82,  80,  76,  77,  78,  15,
  2478.   43,  48,  71,  72,  65,  14, 118,  32,  33,  67,
  2479.  108,  73, 109,  42,  47,  99,  10,  35,  79,  81,
  2480.  151,  82,  80,  76,  77,  78,  15, 100,  85,  71,
  2481.   72,  65,  14, 118,   9,  92,  67,   6,  73, 111,
  2482.  110, 147, 103,   5, 140,  79,  81, 136,  82,  80,
  2483.   76,  77,  78,  15, 102,  13,  71,  72,  65,  14,
  2484.   54,  15,  24,  67,  69,  73,  62,  14, 104,  17,
  2485.  131, 142,  79,  81,  82,  80,  76,  77,  78,  15,
  2486.   60,  53,  71,  72,  65,  14,  54,  45,  58,  67,
  2487.   51,  73,   2, 146,   7,  70,  84,  52,  79,  81,
  2488.   82,  80,  76,  77,  78,  15,  89,  49,  71,  72,
  2489.   65,  14,  54,  94,  46,  67,  30,  73,  82,  80,
  2490.   76,  77,  78,  15,  79,  81,  71,  72,  65,  14,
  2491.  118,  22,  25,  67,  91,  73,  63,   4,   8,  25,
  2492.   34,  12,  79,  81,  21,  26,  23,  25,  28, 101,
  2493.   27,  29,  26,  85,  96,  28,  34,  27,  29,  95,
  2494.   26,  32,  33,  28,  31,  27,  29, 124,  20,  88,
  2495.    1, 137, 135,  97, 115,  41, 117,  32,  33, 120,
  2496.  113, 114,  66,  39, 153, 119, 149, 141, 123,  64,
  2497.  143, 139, 138,  50,  16,   3,  11,  20,  19,  44,
  2498.   75, 105, 137,  83, 106, 148,  38,  61,  59,  57,
  2499.   55,  87,  56,  18, 124,  74,  86,  68,   0,  98,
  2500.    0, 154,   0,   0, 156,   0,   0,   0,   0,   0,
  2501.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  2502.    0,   0,   0,   0,   0,   0,   0,   0, 112,   0,
  2503.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  2504.    0,   0, 130,   0,   0,   0,   0,   0,   0,   0,
  2505.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  2506.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  2507.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  2508.    0,   0,   0,   0,   0,   0,   0,   0,   0, 130 };
  2509. short yypact[]={
  2510.  
  2511. -159,-159,-1000,-180,-141,-1000,-1000,-1000, -65,-1000,
  2512. -1000,-210,-193,-1000,-1000,-1000,-256,-1000,-210,-223,
  2513. -196,-1000,-1000,-196, -72,-1000,-1000,-1000,-1000,-1000,
  2514. -1000,-195,-1000,-1000,-1000,-1000,-1000, -65,-123,-181,
  2515. -196,-1000,-1000,-1000,-1000,-1000, -40,-1000,-1000,-1000,
  2516. -255,-1000, -97,-1000,-168,-273,-1000,-1000, -57, -57,
  2517. -194,-182,-1000,-1000,-1000,-1000,-1000, -97,-1000,-1000,
  2518. -1000,-155,-1000,-221,-1000,-1000,-1000,-1000,-1000,-202,
  2519. -1000,-158,-1000, -56,-1000,-1000,-1000,-1000,-1000,-1000,
  2520. -123,-1000, -97,-1000,-226, -79, -79,-226, -79,-1000,
  2521. -1000,-229,-230,-1000,-176,-149,-260,-1000,-1000,-156,
  2522. -1000,-1000,-1000,-1000,-1000,-1000, -79,-194,-1000, -72,
  2523. -194,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
  2524. -1000,-1000,-237,-1000,-158,-203,-1000,-1000,-242,-149,
  2525. -1000,-267, -97,-1000,-1000,-1000,-239,-1000, -72,-257,
  2526. -1000,-1000,-1000,-1000,-268,-1000,-1000,-1000,-1000,-1000,
  2527. -1000 };
  2528. short yypgo[]={
  2529.  
  2530.    0, 114, 277, 196, 219, 122, 275, 273, 272, 270,
  2531.  148, 140, 269, 268, 267, 266, 264, 263, 261, 260,
  2532.  258, 173, 256, 255, 129, 254, 126, 128, 253, 150,
  2533.  141, 252, 251, 104, 250, 249, 124, 248, 242, 230,
  2534.  152, 198, 197, 176, 224, 174, 166, 235, 156, 155,
  2535.  153, 130 };
  2536. short yyr1[]={
  2537.  
  2538.    0,  39,  39,  40,  41,  41,  23,  42,  42,  22,
  2539.   22,  22,   3,   3,  43,  43,  45,  45,  45,  25,
  2540.   25,  24,   7,   7,   7,   7,  20,  20,  47,  47,
  2541.   15,  15,  44,  44,  44,  17,  17,  48,  28,  28,
  2542.   46,  46,  29,  29,  30,  30,   9,   9,  12,  12,
  2543.   13,  13,  14,  14,   8,   8,  21,  21,  10,  10,
  2544.    4,   4,   5,   5,   5,   5,   5,  11,  11,  26,
  2545.   26,  26,  26,  26,  26,  26,  38,  38,  27,  27,
  2546.    2,  18,  18,  16,  16,  31,  31,  33,  33,  34,
  2547.   34,  32,  32,  35,  35,  49,  36,  36,  36,  36,
  2548.   36,  36,   6,   6,  19,  19,  37,  37,  37,  37,
  2549.   37,  37,  37,  37,  51,  51,   1,   1,  50,  50 };
  2550. short yyr2[]={
  2551.  
  2552.    0,   1,   2,   4,   1,   1,   3,   1,   1,   1,
  2553.    2,   1,   1,   1,   0,   3,   1,   2,   1,   1,
  2554.    3,   4,   1,   2,   1,   1,   2,   3,   1,   1,
  2555.    0,   3,   1,   1,   1,   1,   2,   1,   1,   3,
  2556.    0,   1,   2,   1,   3,   1,   1,   1,   1,   2,
  2557.    1,   3,   2,   2,   1,   2,   2,   3,   1,   3,
  2558.    1,   2,   1,   1,   1,   1,   1,   1,   2,   1,
  2559.    1,   1,   1,   1,   3,   1,   4,   3,   0,   2,
  2560.    4,   0,   2,   1,   2,   2,   1,   2,   1,   0,
  2561.    1,   2,   3,   1,   3,   2,   1,   1,   1,   1,
  2562.    1,   4,   1,   2,   1,   2,   1,   1,   1,   1,
  2563.    1,   1,   1,   3,   2,   1,   0,   2,   1,   2 };
  2564. short yychk[]={
  2565.  
  2566. -1000, -39, -40, -23, -42, 262, 256, -40, -41, 274,
  2567.  256, -22,  -3, 256, 268, 262, -25, -24,  -7, -20,
  2568.   -4, 269, 256, 271,  -5, 264, 277, 282, 280, 283,
  2569.  -43, -44, 277, 278, 256, 270, 275, 278, -15, -44,
  2570.  271, -47, 269, 256, -47,  -5, -45, 269, 256, -24,
  2571.  -28, -29, 280, -30, 269,  -9,  -8, -12, -10, -13,
  2572.  -11, -14, -26,  -3, -35, 267, -38, 272,  -2, -36,
  2573.  -49, 265, 266, 274,  -6, -19, 259, 260, 261, 281,
  2574.  258, 282, 257, -17, -48, 269, -47, -44, 269, -46,
  2575.  276, -30, 263, 279, -21,  -4, 271, -21,  -4, 269,
  2576.  269, -30,  -1, 257, -27, -18, -16, 270, 272, 274,
  2577.  258, 257, -44, -48, -29, -30, 271, -11, 269, -10,
  2578.  -11, 273, 273, -37, -36, 269, 268, 271, 270, 262,
  2579.   -4, -51, 281, 272, 282, -27, 283, -26, -31, -32,
  2580.  -33, -30, 280, -34, 277, 270, -50, 257, -10,  -1,
  2581.  272, 283, 275, -33, -30, 276, -30, 275, 257, 273,
  2582.  276 };
  2583. short yydef[]={
  2584.  
  2585.    0,  -2,   1,   0,   0,   7,   8,   2,   0,   4,
  2586.    5,  14,   9,  11,  12,  13,   0,  19,  30,  22,
  2587.    0,  24,  25,   0,  60,  62,  63,  64,  65,  66,
  2588.    6,   0,  32,  33,  34,  10,   3,   0,   0,   0,
  2589.    0,  23,  28,  29,  26,  61,   0,  16,  18,  20,
  2590.   40,  38,   0,  43,  70,  45,  46,  47,  54,  48,
  2591.   58,  50,  67,  69,  71,  72,  73,   0,  75,  93,
  2592.  116,   0,  78,  81,  96,  97,  98,  99, 100,   0,
  2593.  102,   0, 104,   0,  35,  37,  27,  15,  17,  21,
  2594.   41,  42,   0,  52,  55,   0,   0,  49,   0,  68,
  2595.   53,   0,   0,  78,   0,  89,   0,  83,  95,   0,
  2596.  103, 105,  31,  36,  39,  44,   0,  59,  70,  56,
  2597.   51,  74,  94, 117, 106, 107, 108, 109, 110, 111,
  2598.  112, 116,   0, 115,  64,   0,  77,  79,   0,  89,
  2599.   86,  90,   0,  88,  82,  84,   0, 118,  57,   0,
  2600.  114,  76,  80,  85,  90,  91,  87, 101, 119, 113,
  2601.   92 };
  2602. #ifndef lint
  2603. static char yaccpar_sccsid[] = "@(#)yaccpar    4.1    (Berkeley)    2/11/83";
  2604. #endif not lint
  2605.  
  2606. #
  2607. # define YYFLAG -1000
  2608. # define YYERROR goto yyerrlab
  2609. # define YYACCEPT return(0)
  2610. # define YYABORT return(1)
  2611.  
  2612. /*    parser for yacc output    */
  2613.  
  2614. #ifdef YYDEBUG
  2615. int yydebug = 0; /* 1 for debugging */
  2616. #endif
  2617. YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  2618. int yychar = -1; /* current input token number */
  2619. int yynerrs = 0;  /* number of errors */
  2620. short yyerrflag = 0;  /* error recovery flag */
  2621.  
  2622. yyparse() {
  2623.  
  2624.     short yys[YYMAXDEPTH];
  2625.     short yyj, yym;
  2626.     register YYSTYPE *yypvt;
  2627.     register short yystate, *yyps, yyn;
  2628.     register YYSTYPE *yypv;
  2629.     register short *yyxi;
  2630.  
  2631.     yystate = 0;
  2632.     yychar = -1;
  2633.     yynerrs = 0;
  2634.     yyerrflag = 0;
  2635.     yyps= &yys[-1];
  2636.     yypv= &yyv[-1];
  2637.  
  2638.  yystack:    /* put a state and value onto the stack */
  2639.  
  2640. #ifdef YYDEBUG
  2641.     if( yydebug  ) printf( "state %d, char 0%o\n", yystate, yychar );
  2642. #endif
  2643.         if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
  2644.         *yyps = yystate;
  2645.         ++yypv;
  2646.         *yypv = yyval;
  2647.  
  2648.  yynewstate:
  2649.  
  2650.     yyn = yypact[yystate];
  2651.  
  2652.     if( yyn<= YYFLAG ) goto yydefault; /* simple state */
  2653.  
  2654.     if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
  2655.     if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
  2656.  
  2657.     if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
  2658.         yychar = -1;
  2659.         yyval = yylval;
  2660.         yystate = yyn;
  2661.         if( yyerrflag > 0 ) --yyerrflag;
  2662.         goto yystack;
  2663.         }
  2664.  
  2665.  yydefault:
  2666.     /* default state action */
  2667.  
  2668.     if( (yyn=yydef[yystate]) == -2 ) {
  2669.         if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
  2670.         /* look through exception table */
  2671.  
  2672.         for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
  2673.  
  2674.         while( *(yyxi+=2) >= 0 ){
  2675.             if( *yyxi == yychar ) break;
  2676.             }
  2677.         if( (yyn = yyxi[1]) < 0 ) return(0);   /* accept */
  2678.         }
  2679.  
  2680.     if( yyn == 0 ){ /* error */
  2681.         /* error ... attempt to resume parsing */
  2682.  
  2683.         switch( yyerrflag ){
  2684.  
  2685.         case 0:   /* brand new error */
  2686.  
  2687.             yyerror( "syntax error" );
  2688.         yyerrlab:
  2689.             ++yynerrs;
  2690.  
  2691.         case 1:
  2692.         case 2: /* incompletely recovered error ... try again */
  2693.  
  2694.             yyerrflag = 3;
  2695.  
  2696.             /* find a state where "error" is a legal shift action */
  2697.  
  2698.             while ( yyps >= yys ) {
  2699.                yyn = yypact[*yyps] + YYERRCODE;
  2700.                if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
  2701.                   yystate = yyact[yyn];  /* simulate a shift of "error" */
  2702.                   goto yystack;
  2703.                   }
  2704.                yyn = yypact[*yyps];
  2705.  
  2706.                /* the current yyps has no shift onn "error", pop stack */
  2707.  
  2708. #ifdef YYDEBUG
  2709.                if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
  2710. #endif
  2711.                --yyps;
  2712.                --yypv;
  2713.                }
  2714.  
  2715.             /* there is no state on the stack with an error shift ... abort */
  2716.  
  2717.     yyabort:
  2718.             return(1);
  2719.  
  2720.  
  2721.         case 3:  /* no shift yet; clobber input char */
  2722.  
  2723. #ifdef YYDEBUG
  2724.             if( yydebug ) printf( "error recovery discards char %d\n", yychar );
  2725. #endif
  2726.  
  2727.             if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  2728.             yychar = -1;
  2729.             goto yynewstate;   /* try again in the same state */
  2730.  
  2731.             }
  2732.  
  2733.         }
  2734.  
  2735.     /* reduction by production yyn */
  2736.  
  2737. #ifdef YYDEBUG
  2738.         if( yydebug ) printf("reduce %d\n",yyn);
  2739. #endif
  2740.         yyps -= yyr2[yyn];
  2741.         yypvt = yypv;
  2742.         yypv -= yyr2[yyn];
  2743.         yyval = yypv[1];
  2744.         yym=yyn;
  2745.             /* consult goto table to find next state */
  2746.         yyn = yyr1[yyn];
  2747.         yyj = yypgo[yyn] + *yyps + 1;
  2748.         if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
  2749.         switch(yym){
  2750.             
  2751. case 3:
  2752. # line 103 "parser.y"
  2753. {if (errorcount == 0) genclass(yypvt[-3].l, yypvt[-1].m);} break;
  2754. case 5:
  2755. # line 107 "parser.y"
  2756. {if ((yytext[0] == ':') ||
  2757.                              isalpha(yytext[0])) expect(":SuperClass");
  2758.                          else expect("open brace [");} break;
  2759. case 6:
  2760. # line 112 "parser.y"
  2761. {yyval.l = yypvt[-1].l;} break;
  2762. case 8:
  2763. # line 116 "parser.y"
  2764. {expect("keyword Class");} break;
  2765. case 9:
  2766. # line 119 "parser.y"
  2767. {yyval.l = mkclass(yypvt[-0].c, (char *) 0);} break;
  2768. case 10:
  2769. # line 120 "parser.y"
  2770. {yyval.l = mkclass(yypvt[-1].c, yypvt[-0].c);} break;
  2771. case 11:
  2772. # line 121 "parser.y"
  2773. {expect("Classname :Superclass");
  2774.                                          yyval.l = mkclass("Error", (char *) 0);} break;
  2775. case 16:
  2776. # line 133 "parser.y"
  2777. {addinst(yypvt[-0].c);} break;
  2778. case 17:
  2779. # line 134 "parser.y"
  2780. {addinst(yypvt[-0].c);} break;
  2781. case 18:
  2782. # line 135 "parser.y"
  2783. {expect("instance variable");} break;
  2784. case 20:
  2785. # line 140 "parser.y"
  2786. {yypvt[-0].m->nextmethod = yypvt[-2].m; yyval.m = yypvt[-0].m;} break;
  2787. case 21:
  2788. # line 144 "parser.y"
  2789. {deltemps(yypvt[-2].i); yyval.m = mkmethod(yypvt[-3].e, yypvt[-2].i, yypvt[-1].s);} break;
  2790. case 22:
  2791. # line 148 "parser.y"
  2792. {yyval.e = mkkey((struct exprstruct *) 0, yypvt[-0].k);} break;
  2793. case 23:
  2794. # line 150 "parser.y"
  2795. {yyval.e = mkexpr((struct exprstruct *) 0, bincmd, yypvt[-1].c, (struct exprstruct *) 0);} break;
  2796. case 24:
  2797. # line 152 "parser.y"
  2798. {yyval.e = mkexpr((struct exprstruct *) 0, uncmd, yypvt[-0].c, (struct exprstruct *) 0);} break;
  2799. case 25:
  2800. # line 153 "parser.y"
  2801. {expect("method pattern");
  2802. yyval.e = mkexpr((struct exprstruct *) 0, uncmd, "", (struct exprstruct *) 0);} break;
  2803. case 26:
  2804. # line 158 "parser.y"
  2805. {yyval.k = mkklist((struct keylist *) 0, yypvt[-1].c, (struct exprstruct *) 0);} break;
  2806. case 27:
  2807. # line 160 "parser.y"
  2808. {yyval.k = mkklist(yypvt[-2].k, yypvt[-1].c, (struct exprstruct *) 0);} break;
  2809. case 28:
  2810. # line 163 "parser.y"
  2811. {addtemp(yypvt[-0].c, argvar);} break;
  2812. case 29:
  2813. # line 164 "parser.y"
  2814. {expect("argument variable");} break;
  2815. case 30:
  2816. # line 167 "parser.y"
  2817. {yyval.i = 0;} break;
  2818. case 31:
  2819. # line 168 "parser.y"
  2820. {yyval.i = yypvt[-1].i;} break;
  2821. case 34:
  2822. # line 173 "parser.y"
  2823. {expect("| (vertical bar)");} break;
  2824. case 35:
  2825. # line 176 "parser.y"
  2826. {yyval.i = 1;} break;
  2827. case 36:
  2828. # line 177 "parser.y"
  2829. {yyval.i = yypvt[-1].i + 1;} break;
  2830. case 37:
  2831. # line 180 "parser.y"
  2832. {addtemp(yypvt[-0].c, tempvar);} break;
  2833. case 38:
  2834. # line 183 "parser.y"
  2835. {yyval.s = yypvt[-0].s;} break;
  2836. case 39:
  2837. # line 184 "parser.y"
  2838. {yypvt[-0].s->nextstate = yypvt[-2].s; yyval.s = yypvt[-0].s;} break;
  2839. case 42:
  2840. # line 191 "parser.y"
  2841. {yyval.s = mkstate(upar, (char *) 0, yypvt[-0].s);} break;
  2842. case 44:
  2843. # line 196 "parser.y"
  2844. {yyval.s = mkstate(asgn, yypvt[-2].c, yypvt[-0].s);} break;
  2845. case 45:
  2846. # line 198 "parser.y"
  2847. {yyval.s = mkstate(expr, (char *) 0, (struct statestruct *) yypvt[-0].e);} break;
  2848. case 47:
  2849. # line 202 "parser.y"
  2850. {yyval.e = mkexpr(yypvt[-0].e, semiend, 0, 0);} break;
  2851. case 49:
  2852. # line 206 "parser.y"
  2853. {yyval.e = mkkey(yypvt[-1].e, yypvt[-0].k);} break;
  2854. case 51:
  2855. # line 211 "parser.y"
  2856. {yyval.e = mkexpr(yypvt[-2].e, bincmd, yypvt[-1].c, yypvt[-0].e);} break;
  2857. case 52:
  2858. # line 214 "parser.y"
  2859. {yyval.e = mkexpr(yypvt[-1].e, semistart, 0, 0);} break;
  2860. case 53:
  2861. # line 216 "parser.y"
  2862. {yyval.e = mkexpr(yypvt[-1].e, uncmd, yypvt[-0].c, (struct exprstruct *) 0);} break;
  2863. case 54:
  2864. # line 219 "parser.y"
  2865. {yyval.e = yypvt[-0].e;} break;
  2866. case 55:
  2867. # line 220 "parser.y"
  2868. {yyval.e = mkkey(yypvt[-1].e, yypvt[-0].k);} break;
  2869. case 56:
  2870. # line 224 "parser.y"
  2871. {yyval.k = mkklist((struct keylist *) 0, yypvt[-1].c, yypvt[-0].e);} break;
  2872. case 57:
  2873. # line 226 "parser.y"
  2874. {yyval.k = mkklist(yypvt[-2].k, yypvt[-1].c, yypvt[-0].e);} break;
  2875. case 58:
  2876. # line 229 "parser.y"
  2877. {yyval.e = yypvt[-0].e;} break;
  2878. case 59:
  2879. # line 230 "parser.y"
  2880. {yyval.e = mkexpr(yypvt[-2].e, bincmd, yypvt[-1].c, yypvt[-0].e);} break;
  2881. case 60:
  2882. # line 233 "parser.y"
  2883. {yyval.c = yypvt[-0].c;} break;
  2884. case 61:
  2885. # line 234 "parser.y"
  2886. {yyval.c = bincat(yypvt[-1].c, yypvt[-0].c);} break;
  2887. case 67:
  2888. # line 245 "parser.y"
  2889. {yyval.e = mkexpr((struct exprstruct *) 0, reccmd, (char *) 0,
  2890.                     (struct exprstruct *) yypvt[-0].o);} break;
  2891. case 68:
  2892. # line 248 "parser.y"
  2893. {yyval.e = mkexpr(yypvt[-1].e, uncmd, yypvt[-0].c, (struct exprstruct *) 0);} break;
  2894. case 69:
  2895. # line 251 "parser.y"
  2896. {e.c = yypvt[-0].c; yyval.o = mkobj(classobj, &e);} break;
  2897. case 70:
  2898. # line 252 "parser.y"
  2899. {e.c = yypvt[-0].c; yyval.o = mkobj(varobj, &e);} break;
  2900. case 71:
  2901. # line 253 "parser.y"
  2902. {e.t = yypvt[-0].t; yyval.o = mkobj(litobj, &e);} break;
  2903. case 72:
  2904. # line 254 "parser.y"
  2905. {e.p = yypvt[-0].p; yyval.o = mkobj(pseuobj, &e);} break;
  2906. case 73:
  2907. # line 255 "parser.y"
  2908. {e.u = yypvt[-0].u; yyval.o = mkobj(primobj, &e);} break;
  2909. case 74:
  2910. # line 256 "parser.y"
  2911. {e.s = yypvt[-1].s; yyval.o = mkobj(exprobj, &e);} break;
  2912. case 75:
  2913. # line 257 "parser.y"
  2914. {e.b = yypvt[-0].b; yyval.o = mkobj(blockobj, &e);} break;
  2915. case 76:
  2916. # line 261 "parser.y"
  2917. {yyval.u = mkprim(yypvt[-2].i, yypvt[-1].r);} break;
  2918. case 77:
  2919. # line 263 "parser.y"
  2920. {yyval.u = mkprim(yypvt[-2].i, yypvt[-1].r);} break;
  2921. case 78:
  2922. # line 266 "parser.y"
  2923. {yyval.r = (struct primlist *) 0;} break;
  2924. case 79:
  2925. # line 267 "parser.y"
  2926. {yyval.r = addprim(yypvt[-1].r, yypvt[-0].o);} break;
  2927. case 80:
  2928. # line 271 "parser.y"
  2929. {yyval.b = mkblock(yypvt[-2].i, yypvt[-1].s);
  2930.                     deltemps(yypvt[-2].i);} break;
  2931. case 81:
  2932. # line 275 "parser.y"
  2933. {yyval.i = 0;} break;
  2934. case 82:
  2935. # line 276 "parser.y"
  2936. {yyval.i = yypvt[-1].i;} break;
  2937. case 83:
  2938. # line 279 "parser.y"
  2939. {addtemp(yypvt[-0].c, argvar); yyval.i = 1;} break;
  2940. case 84:
  2941. # line 280 "parser.y"
  2942. {addtemp(yypvt[-0].c, argvar); yyval.i = yypvt[-1].i + 1;} break;
  2943. case 85:
  2944. # line 283 "parser.y"
  2945. {yypvt[-0].s->nextstate = yypvt[-1].s; yyval.s = yypvt[-0].s;} break;
  2946. case 86:
  2947. # line 284 "parser.y"
  2948. {yyval.s = yypvt[-0].s;} break;
  2949. case 87:
  2950. # line 287 "parser.y"
  2951. {yyval.s = mkstate(blkupar, (char *) 0, yypvt[-0].s);} break;
  2952. case 88:
  2953. # line 288 "parser.y"
  2954. {yyval.s = mkstate(upar, (char *) 0, yypvt[-0].s);} break;
  2955. case 89:
  2956. # line 292 "parser.y"
  2957. {e.p = nilvar;
  2958. yyval.s = mkstate(expr, (char *) 0,
  2959. (struct statestruct *) mkexpr((struct exprstruct *) 0, reccmd, (char *) 0,
  2960.     (struct exprstruct *) mkobj(pseuobj, &e)));} break;
  2961. case 90:
  2962. # line 296 "parser.y"
  2963. {yyval.s = yypvt[-0].s;} break;
  2964. case 91:
  2965. # line 299 "parser.y"
  2966. {yyval.s = yypvt[-1].s;} break;
  2967. case 92:
  2968. # line 301 "parser.y"
  2969. {yypvt[-1].s->nextstate = yypvt[-2].s; yyval.s = yypvt[-1].s;} break;
  2970. case 93:
  2971. # line 304 "parser.y"
  2972. {yyval.t = yypvt[-0].t;} break;
  2973. case 94:
  2974. # line 305 "parser.y"
  2975. {e.a = yypvt[-1].a; yyval.t = mklit(arlit, &e);} break;
  2976. case 96:
  2977. # line 311 "parser.y"
  2978. {e.c = yypvt[-0].c; yyval.t = mklit(fnumlit, &e);} break;
  2979. case 97:
  2980. # line 312 "parser.y"
  2981. {e.i = yypvt[-0].i; yyval.t = mklit(numlit, &e);} break;
  2982. case 98:
  2983. # line 313 "parser.y"
  2984. {e.i = yypvt[-0].i; yyval.t = mklit(charlit, &e);} break;
  2985. case 99:
  2986. # line 314 "parser.y"
  2987. {e.c = yypvt[-0].c; yyval.t = mklit(strlit, &e);} break;
  2988. case 100:
  2989. # line 315 "parser.y"
  2990. {e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
  2991. case 101:
  2992. # line 316 "parser.y"
  2993. {bytearray[bytetop] = '\0';
  2994.                                          yyval.t = mklit(bytelit, &e);} break;
  2995. case 102:
  2996. # line 320 "parser.y"
  2997. {yyval.c = yypvt[-0].c;} break;
  2998. case 103:
  2999. # line 321 "parser.y"
  3000. {yyval.c = bincat("-", yypvt[-0].c);} break;
  3001. case 104:
  3002. # line 324 "parser.y"
  3003. {yyval.i = yypvt[-0].i;} break;
  3004. case 105:
  3005. # line 325 "parser.y"
  3006. {yyval.i = - yypvt[-0].i;} break;
  3007. case 106:
  3008. # line 328 "parser.y"
  3009. {yyval.t = yypvt[-0].t;} break;
  3010. case 107:
  3011. # line 329 "parser.y"
  3012. {e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
  3013. case 108:
  3014. # line 330 "parser.y"
  3015. {e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
  3016. case 109:
  3017. # line 331 "parser.y"
  3018. {e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
  3019. case 110:
  3020. # line 332 "parser.y"
  3021. {e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
  3022. case 111:
  3023. # line 333 "parser.y"
  3024. {e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
  3025. case 112:
  3026. # line 334 "parser.y"
  3027. {e.c = yypvt[-0].c; yyval.t = mklit(symlit, &e);} break;
  3028. case 113:
  3029. # line 335 "parser.y"
  3030. {e.a = yypvt[-1].a; yyval.t = mklit(arlit, &e);} break;
  3031. case 116:
  3032. # line 342 "parser.y"
  3033. {yyval.a = (struct litlist *) 0;} break;
  3034. case 117:
  3035. # line 343 "parser.y"
  3036. {yyval.a = addlit(yypvt[-1].a, yypvt[-0].t);} break;
  3037. case 118:
  3038. # line 346 "parser.y"
  3039. {bytetop = 0;
  3040.                                          bytearray[bytetop++] = itouc(yypvt[-0].i);} break;
  3041. case 119:
  3042. # line 348 "parser.y"
  3043. {bytearray[bytetop++] = itouc(yypvt[-0].i);} break;
  3044.         }
  3045.         goto yystack;  /* stack new state and value */
  3046.  
  3047.     }
  3048. End
  3049. echo unbundling lex.yy.c 1>&2
  3050. cat >lex.yy.c <<'End'
  3051. # include "stdio.h"
  3052. # define U(x) x
  3053. # define NLSTATE yyprevious=YYNEWLINE
  3054. # define BEGIN yybgin = yysvec + 1 +
  3055. # define INITIAL 0
  3056. # define YYLERR yysvec
  3057. # define YYSTATE (yyestate-yysvec-1)
  3058. # define YYOPTIM 1
  3059. # define YYLMAX 200
  3060. # define output(c) putc(c,yyout)
  3061. # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
  3062. # define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
  3063. # define yymore() (yymorfg=1)
  3064. # define ECHO fprintf(yyout, "%s",yytext)
  3065. # define REJECT { nstr = yyreject(); goto yyfussy;}
  3066. int yyleng; extern char yytext[];
  3067. int yymorfg;
  3068. extern char *yysptr, yysbuf[];
  3069. int yytchar;
  3070. FILE *yyin ={stdin}, *yyout ={stdout};
  3071. extern int yylineno;
  3072. struct yysvf {
  3073.     struct yywork *yystoff;
  3074.     struct yysvf *yyother;
  3075.     int *yystops;};
  3076. struct yysvf *yyestate;
  3077. extern struct yysvf yysvec[], *yybgin;
  3078. /*
  3079.         Little Smalltalk lexical analyzer
  3080. */
  3081. # include <math.h>
  3082. # include "primnum.h"
  3083.  
  3084. # undef input
  3085. # undef unput
  3086.  
  3087. double atof();
  3088. int linenum = 1;
  3089. # define YYNEWLINE 10
  3090. yylex(){
  3091. int nstr; extern int yyprevious;
  3092. while((nstr = yylook()) >= 0)
  3093. yyfussy: switch(nstr){
  3094. case 0:
  3095. if(yywrap()) return(0); break;
  3096. case 1:
  3097.                          {;}
  3098. break;
  3099. case 2:
  3100.                              {linenum++;}
  3101. break;
  3102. case 3:
  3103.                              {readcomment();}
  3104. break;
  3105. case 4:
  3106.                            {return(ASSIGN);}
  3107. break;
  3108. case 5:
  3109.                            {return(ASSIGN);}
  3110. break;
  3111. case 6:
  3112.                           {return(lexsave(CLASS));}
  3113. break;
  3114. case 7:
  3115.                            {yylval.p = selfvar;  return(PSEUDO);}
  3116. break;
  3117. case 8:
  3118.         {yylval.p = procvar;  return(PSEUDO);}
  3119. break;
  3120. case 9:
  3121.                           {yylval.p = supervar; return(PSEUDO);}
  3122. break;
  3123. case 10:
  3124.                             {yylval.p = nilvar;   return(PSEUDO);}
  3125. break;
  3126. case 11:
  3127.                            {yylval.p = truevar;  return(PSEUDO);}
  3128. break;
  3129. case 12:
  3130.                           {yylval.p = falsevar; return(PSEUDO);}
  3131. break;
  3132. case 13:
  3133.                       {yylval.p = smallvar; return(PSEUDO);}
  3134. break;
  3135. case 14:
  3136.                             {yylval.i = yytext[1]; return(LITCHAR);}
  3137. break;
  3138. case 15:
  3139.                               {return(PS);}
  3140. break;
  3141. case 16:
  3142. {return(lexsave(LITFNUM));}
  3143. break;
  3144. case 17:
  3145.                          {yylval.i = atoi(yytext); return(LITNUM);}
  3146. break;
  3147. case 18:
  3148.   {return(lexsave(LITFNUM));}
  3149. break;
  3150. case 19:
  3151.                         {char c; unput(c = input());
  3152.                                  if (c == '\'') yymore();
  3153.                                  else return(lexlstr());}
  3154. break;
  3155. case 20:
  3156.                  {return(varlex());}
  3157. break;
  3158. case 21:
  3159.                   {return(slexsave(COLONVAR));}
  3160. break;
  3161. case 22:
  3162.                 {return(slexsave(LITSYM));}
  3163. break;
  3164. case 23:
  3165.                             {return(lexsave(MINUS));}
  3166. break;
  3167. case 24:
  3168.                             {return(LP);}
  3169. break;
  3170. case 25:
  3171.                             {return(RP);}
  3172. break;
  3173. case 26:
  3174.                             {return(LB);}
  3175. break;
  3176. case 27:
  3177.                             {return(RB);}
  3178. break;
  3179. case 28:
  3180.                             {return(PERIOD);}
  3181. break;
  3182. case 29:
  3183.             {return(lexsave(MBAR));}
  3184. break;
  3185. case 30:
  3186.             {return(lexsave(MBAR));}
  3187. break;
  3188. case 31:
  3189.                             {return(lexsave(BAR));}
  3190. break;
  3191. case 32:
  3192.                             {return(lexsave(BAR));}
  3193. break;
  3194. case 33:
  3195.                             {return(SEMI);}
  3196. break;
  3197. case 34:
  3198.                             {return(lexsave(UPARROW));}
  3199. break;
  3200. case 35:
  3201.             {return(lexsave(PE));}
  3202. break;
  3203. case 36:
  3204.               {return(lexsave(BINARY));}
  3205. break;
  3206. case 37:
  3207.               {return(PRIMITIVE);}
  3208. break;
  3209. case 38:
  3210.         {yylval.i = prim_number(&yytext[1]); return(NAMEDPRIM);}
  3211. break;
  3212. case -1:
  3213. break;
  3214. default:
  3215. fprintf(yyout,"bad switch yylook %d",nstr);
  3216. } return(0); }
  3217. /* end of yylex */
  3218. static int ocbuf = 0;
  3219. static int pbbuf[400];
  3220.  
  3221. static int input()
  3222. {    int c;
  3223.  
  3224.     if (ocbuf) {c = pbbuf[--ocbuf]; }
  3225.     else {
  3226.         c = getc(fp);
  3227.         if (c == EOF) c = 0;
  3228.         }
  3229.     return(c);
  3230. }
  3231.  
  3232. static unput(c)
  3233. char c;
  3234. {
  3235.     if (c) pbbuf[ocbuf++] = c;
  3236. }
  3237.  
  3238. # include <ctype.h>
  3239.  
  3240. static readcomment()
  3241. {  char c;
  3242.  
  3243.    while ((c = input()) && c != '\"')
  3244.     if (c == '\n') linenum++;
  3245.    if (!c) yyerror("unterminated comment");
  3246. }
  3247.  
  3248. char *walloc(s) char *s;
  3249. {  char *p, *malloc();
  3250.  
  3251.    p = malloc((unsigned) (strlen(s) + 1));
  3252.    if (p == (char *) 0) yyerror("out of variable string space");
  3253.    strcpy(p, s);
  3254.    return(p);
  3255. }
  3256.  
  3257. static int slexsave(type)
  3258. int type;
  3259. {
  3260.  
  3261.     yylval.c = walloc(&yytext[1]);
  3262.     if (yylval.c == 0) yerr("cannot create symbol %s", yytext);
  3263.     return(type);
  3264. }
  3265.  
  3266. static int lexsave(type)
  3267. int type;
  3268. {
  3269.  
  3270.     yylval.c = walloc(yytext);
  3271.     if (yylval.c == 0) yerr("cannot create string %s", yytext);
  3272.     return(type);
  3273. }
  3274.  
  3275. static int varlex()
  3276. {
  3277.  
  3278.    lexsave(0);
  3279.    if (yytext[yyleng-1] == ':') return(KEYWORD);
  3280.    else if (islower(yytext[0])) return(LOWERCASEVAR);
  3281.    else return(UPPERCASEVAR);
  3282. }
  3283.  
  3284. static int lexlstr()
  3285. {  char *p, *q;
  3286.  
  3287.    yylval.c = p = walloc(&yytext[1]);
  3288.    *(p + yyleng -2) = '\0';
  3289.    return(LITSTR);
  3290. }
  3291.  
  3292. static int prim_number(name)
  3293. char *name;
  3294. {    struct prim_names *p;
  3295.  
  3296.     for (p = prim_table; *(p->p_name); p++) {
  3297.         if (strcmp(p->p_name, name) == 0)
  3298.             return(p->p_number);
  3299.         }
  3300.     yerr("unknown primitive name %s", name);
  3301.     return(0);
  3302. }
  3303. int yyvstop[] ={
  3304. 0,
  3305.  
  3306. 36,
  3307. 0,
  3308.  
  3309. 1,
  3310. 0,
  3311.  
  3312. 2,
  3313. 0,
  3314.  
  3315. 32,
  3316. 36,
  3317. 0,
  3318.  
  3319. 3,
  3320. 36,
  3321. 0,
  3322.  
  3323. 15,
  3324. 36,
  3325. 0,
  3326.  
  3327. 36,
  3328. 0,
  3329.  
  3330. 36,
  3331. 0,
  3332.  
  3333. 24,
  3334. 36,
  3335. 0,
  3336.  
  3337. 25,
  3338. 36,
  3339. 0,
  3340.  
  3341. 23,
  3342. 36,
  3343. 0,
  3344.  
  3345. 28,
  3346. 36,
  3347. 0,
  3348.  
  3349. 17,
  3350. 18,
  3351. 20,
  3352. 0,
  3353.  
  3354. 36,
  3355. 0,
  3356.  
  3357. 33,
  3358. 36,
  3359. 0,
  3360.  
  3361. 36,
  3362. 0,
  3363.  
  3364. 35,
  3365. 36,
  3366. 0,
  3367.  
  3368. 20,
  3369. 0,
  3370.  
  3371. 20,
  3372. 0,
  3373.  
  3374. 26,
  3375. 36,
  3376. 0,
  3377.  
  3378. 27,
  3379. 36,
  3380. 0,
  3381.  
  3382. 34,
  3383. 36,
  3384. 0,
  3385.  
  3386. 20,
  3387. 0,
  3388.  
  3389. 20,
  3390. 0,
  3391.  
  3392. 20,
  3393. 0,
  3394.  
  3395. 20,
  3396. 0,
  3397.  
  3398. 31,
  3399. 36,
  3400. 0,
  3401.  
  3402. 30,
  3403. 32,
  3404. 36,
  3405. 0,
  3406.  
  3407. 29,
  3408. 31,
  3409. 36,
  3410. 0,
  3411.  
  3412. 22,
  3413. 0,
  3414.  
  3415. 14,
  3416. 0,
  3417.  
  3418. 19,
  3419. 0,
  3420.  
  3421. 20,
  3422. 0,
  3423.  
  3424. 20,
  3425. 0,
  3426.  
  3427. 20,
  3428. 0,
  3429.  
  3430. 21,
  3431. 0,
  3432.  
  3433. 4,
  3434. 0,
  3435.  
  3436. 5,
  3437. 0,
  3438.  
  3439. 38,
  3440. 0,
  3441.  
  3442. 38,
  3443. 0,
  3444.  
  3445. 20,
  3446. 0,
  3447.  
  3448. 20,
  3449. 0,
  3450.  
  3451. 20,
  3452. 0,
  3453.  
  3454. 20,
  3455. 0,
  3456.  
  3457. 20,
  3458. 0,
  3459.  
  3460. 20,
  3461. 0,
  3462.  
  3463. 20,
  3464. 0,
  3465.  
  3466. 18,
  3467. 0,
  3468.  
  3469. 18,
  3470. 20,
  3471. 0,
  3472.  
  3473. 16,
  3474. 20,
  3475. 0,
  3476.  
  3477. 38,
  3478. 0,
  3479.  
  3480. 20,
  3481. 0,
  3482.  
  3483. 20,
  3484. 0,
  3485.  
  3486. 10,
  3487. 20,
  3488. 0,
  3489.  
  3490. 20,
  3491. 0,
  3492.  
  3493. 20,
  3494. 0,
  3495.  
  3496. 20,
  3497. 0,
  3498.  
  3499. 20,
  3500. 0,
  3501.  
  3502. 18,
  3503. 0,
  3504.  
  3505. 16,
  3506. 0,
  3507.  
  3508. 20,
  3509. 0,
  3510.  
  3511. 38,
  3512. 0,
  3513.  
  3514. 20,
  3515. 0,
  3516.  
  3517. 20,
  3518. 0,
  3519.  
  3520. 7,
  3521. 20,
  3522. 0,
  3523.  
  3524. 20,
  3525. 0,
  3526.  
  3527. 20,
  3528. 0,
  3529.  
  3530. 11,
  3531. 20,
  3532. 0,
  3533.  
  3534. 16,
  3535. 0,
  3536.  
  3537. 16,
  3538. 20,
  3539. 0,
  3540.  
  3541. 38,
  3542. 0,
  3543.  
  3544. 6,
  3545. 20,
  3546. 0,
  3547.  
  3548. 12,
  3549. 20,
  3550. 0,
  3551.  
  3552. 20,
  3553. 0,
  3554.  
  3555. 20,
  3556. 0,
  3557.  
  3558. 9,
  3559. 20,
  3560. 0,
  3561.  
  3562. 16,
  3563. 0,
  3564.  
  3565. 38,
  3566. 0,
  3567.  
  3568. 20,
  3569. 0,
  3570.  
  3571. 20,
  3572. 0,
  3573.  
  3574. 38,
  3575. 0,
  3576.  
  3577. 20,
  3578. 0,
  3579.  
  3580. 20,
  3581. 0,
  3582.  
  3583. 38,
  3584. 0,
  3585.  
  3586. 20,
  3587. 0,
  3588.  
  3589. 20,
  3590. 0,
  3591.  
  3592. 38,
  3593. 0,
  3594.  
  3595. 20,
  3596. 0,
  3597.  
  3598. 13,
  3599. 20,
  3600. 0,
  3601.  
  3602. 37,
  3603. 38,
  3604. 0,
  3605.  
  3606. 20,
  3607. 0,
  3608.  
  3609. 8,
  3610. 20,
  3611. 0,
  3612. 0};
  3613. # define YYTYPE char
  3614. struct yywork { YYTYPE verify, advance; } yycrank[] ={
  3615. 0,0,    0,0,    1,3,    0,0,    
  3616. 0,0,    0,0,    0,0,    0,0,    
  3617. 0,0,    0,0,    1,4,    1,5,    
  3618. 0,0,    0,0,    0,0,    4,4,    
  3619. 0,0,    0,0,    0,0,    0,0,    
  3620. 0,0,    0,0,    0,0,    0,0,    
  3621. 0,0,    0,0,    0,0,    0,0,    
  3622. 0,0,    0,0,    0,0,    0,0,    
  3623. 0,0,    0,0,    1,6,    1,7,    
  3624. 1,8,    1,9,    4,4,    0,0,    
  3625. 1,10,    1,11,    1,12,    0,0,    
  3626. 1,3,    0,0,    1,13,    1,14,    
  3627. 0,0,    1,15,    0,0,    0,0,    
  3628. 0,0,    0,0,    0,0,    0,0,    
  3629. 0,0,    0,0,    0,0,    1,16,    
  3630. 1,17,    1,18,    0,0,    1,19,    
  3631. 0,0,    0,0,    1,20,    0,0,    
  3632. 1,21,    0,0,    0,0,    65,53,    
  3633. 0,0,    65,53,    0,0,    2,30,    
  3634. 2,7,    2,8,    2,9,    0,0,    
  3635. 0,0,    8,32,    0,0,    2,12,    
  3636. 0,0,    0,0,    0,0,    2,13,    
  3637. 2,14,    8,0,    8,0,    0,0,    
  3638. 1,22,    0,0,    1,23,    1,24,    
  3639. 0,0,    0,0,    1,20,    9,33,    
  3640. 2,16,    2,17,    2,18,    1,25,    
  3641. 2,19,    25,46,    45,58,    9,33,    
  3642. 9,0,    2,21,    21,45,    1,26,    
  3643. 8,0,    26,47,    46,59,    47,60,    
  3644. 1,27,    1,28,    28,51,    8,32,    
  3645. 8,0,    8,0,    10,34,    8,32,    
  3646. 27,48,    1,29,    8,0,    44,57,    
  3647. 8,32,    48,61,    10,34,    10,34,    
  3648. 27,49,    2,22,    49,62,    2,23,    
  3649. 2,24,    9,33,    9,33,    50,63,    
  3650. 27,50,    9,33,    51,64,    52,65,    
  3651. 2,25,    8,32,    9,33,    57,70,    
  3652. 58,71,    59,72,    61,73,    62,74,    
  3653. 2,26,    63,75,    64,76,    70,81,    
  3654. 71,82,    2,27,    2,28,    67,68,    
  3655. 10,35,    10,34,    72,83,    9,33,    
  3656. 10,34,    73,84,    2,31,    74,85,    
  3657. 75,86,    10,34,    78,77,    8,0,    
  3658. 81,88,    84,89,    85,90,    88,91,    
  3659. 89,92,    8,32,    90,93,    91,94,    
  3660. 92,95,    93,96,    94,97,    95,98,    
  3661. 96,99,    97,100,    10,34,    98,101,    
  3662. 101,102,    0,0,    0,0,    0,0,    
  3663. 0,0,    0,0,    0,0,    9,33,    
  3664. 0,0,    0,0,    0,0,    0,0,    
  3665. 15,36,    0,0,    15,15,    15,15,    
  3666. 15,15,    15,15,    15,15,    15,15,    
  3667. 15,15,    15,15,    15,15,    15,15,    
  3668. 15,37,    0,0,    67,77,    0,0,    
  3669. 0,0,    0,0,    10,34,    15,20,    
  3670. 15,20,    15,20,    15,20,    15,20,    
  3671. 15,20,    15,20,    15,20,    15,20,    
  3672. 15,20,    15,20,    15,20,    15,20,    
  3673. 15,20,    15,20,    15,20,    15,20,    
  3674. 15,20,    15,20,    15,20,    15,20,    
  3675. 15,20,    15,20,    15,20,    15,20,    
  3676. 15,20,    0,0,    0,0,    0,0,    
  3677. 0,0,    0,0,    0,0,    15,20,    
  3678. 15,20,    15,20,    15,20,    15,38,    
  3679. 15,20,    15,20,    15,20,    15,20,    
  3680. 15,20,    15,20,    15,20,    15,20,    
  3681. 15,20,    15,20,    15,20,    15,20,    
  3682. 15,39,    15,20,    15,20,    15,20,    
  3683. 15,20,    15,20,    15,20,    15,20,    
  3684. 15,20,    16,40,    16,40,    16,40,    
  3685. 16,40,    16,40,    16,40,    16,40,    
  3686. 16,40,    16,40,    16,40,    0,0,    
  3687. 0,0,    0,0,    16,41,    0,0,    
  3688. 0,0,    0,0,    16,40,    16,40,    
  3689. 16,40,    16,40,    16,40,    16,40,    
  3690. 16,40,    16,40,    16,40,    16,40,    
  3691. 16,40,    16,40,    16,40,    16,40,    
  3692. 16,40,    16,40,    16,40,    16,40,    
  3693. 16,40,    16,40,    16,40,    16,40,    
  3694. 16,40,    16,40,    16,40,    16,40,    
  3695. 0,0,    0,0,    0,0,    0,0,    
  3696. 0,0,    0,0,    16,40,    16,40,    
  3697. 16,40,    16,40,    16,40,    16,40,    
  3698. 16,40,    16,40,    16,40,    16,40,    
  3699. 16,40,    16,40,    16,40,    16,40,    
  3700. 16,40,    16,40,    16,40,    16,40,    
  3701. 16,40,    16,40,    16,40,    16,40,    
  3702. 16,40,    16,40,    16,40,    16,40,    
  3703. 18,42,    0,0,    0,0,    18,43,    
  3704. 18,43,    18,43,    18,43,    18,43,    
  3705. 18,43,    18,43,    18,43,    18,43,    
  3706. 18,43,    0,0,    0,0,    0,0,    
  3707. 0,0,    0,0,    0,0,    0,0,    
  3708. 18,43,    18,43,    18,43,    18,43,    
  3709. 18,43,    18,43,    18,43,    18,43,    
  3710. 18,43,    18,43,    18,43,    18,43,    
  3711. 18,43,    18,43,    18,43,    18,43,    
  3712. 18,43,    18,43,    18,43,    18,43,    
  3713. 18,43,    18,43,    18,43,    18,43,    
  3714. 18,43,    18,43,    0,0,    0,0,    
  3715. 0,0,    0,0,    0,0,    0,0,    
  3716. 18,43,    18,43,    18,43,    18,43,    
  3717. 18,43,    18,43,    18,43,    18,43,    
  3718. 18,43,    18,43,    18,43,    18,43,    
  3719. 18,43,    18,43,    18,43,    18,44,    
  3720. 18,43,    18,43,    18,43,    18,43,    
  3721. 18,43,    18,43,    18,43,    18,43,    
  3722. 18,43,    18,43,    20,20,    20,20,    
  3723. 20,20,    20,20,    20,20,    20,20,    
  3724. 20,20,    20,20,    20,20,    20,20,    
  3725. 20,37,    0,0,    0,0,    0,0,    
  3726. 0,0,    0,0,    0,0,    20,20,    
  3727. 20,20,    20,20,    20,20,    20,20,    
  3728. 20,20,    20,20,    20,20,    20,20,    
  3729. 20,20,    20,20,    20,20,    20,20,    
  3730. 20,20,    20,20,    20,20,    20,20,    
  3731. 20,20,    20,20,    20,20,    20,20,    
  3732. 20,20,    20,20,    20,20,    20,20,    
  3733. 20,20,    0,0,    0,0,    0,0,    
  3734. 0,0,    0,0,    0,0,    20,20,    
  3735. 20,20,    20,20,    20,20,    20,20,    
  3736. 20,20,    20,20,    20,20,    20,20,    
  3737. 20,20,    20,20,    20,20,    20,20,    
  3738. 20,20,    20,20,    20,20,    20,20,    
  3739. 20,20,    20,20,    20,20,    20,20,    
  3740. 20,20,    20,20,    20,20,    20,20,    
  3741. 20,20,    32,0,    32,0,    36,52,    
  3742. 36,52,    36,52,    36,52,    36,52,    
  3743. 36,52,    36,52,    36,52,    36,52,    
  3744. 36,52,    53,66,    53,66,    53,66,    
  3745. 53,66,    53,66,    53,66,    53,66,    
  3746. 53,66,    53,66,    53,66,    0,0,    
  3747. 32,0,    0,0,    0,0,    0,0,    
  3748. 0,0,    0,0,    0,0,    0,0,    
  3749. 32,0,    32,0,    38,53,    0,0,    
  3750. 38,53,    0,0,    32,0,    38,54,    
  3751. 38,54,    38,54,    38,54,    38,54,    
  3752. 38,54,    38,54,    38,54,    38,54,    
  3753. 38,54,    54,54,    54,54,    54,54,    
  3754. 54,54,    54,54,    54,54,    54,54,    
  3755. 54,54,    54,54,    54,54,    0,0,    
  3756. 0,0,    0,0,    0,0,    0,0,    
  3757. 39,55,    0,0,    0,0,    39,56,    
  3758. 39,56,    39,56,    39,56,    39,56,    
  3759. 39,56,    39,56,    39,56,    39,56,    
  3760. 39,56,    0,0,    0,0,    0,0,    
  3761. 0,0,    0,0,    0,0,    32,0,    
  3762. 39,56,    39,56,    39,56,    39,56,    
  3763. 39,56,    39,56,    39,56,    39,56,    
  3764. 39,56,    39,56,    39,56,    39,56,    
  3765. 39,56,    39,56,    39,56,    39,56,    
  3766. 39,56,    39,56,    39,56,    39,56,    
  3767. 39,56,    39,56,    39,56,    39,56,    
  3768. 39,56,    39,56,    40,40,    40,40,    
  3769. 40,40,    40,40,    40,40,    40,40,    
  3770. 40,40,    40,40,    40,40,    40,40,    
  3771. 0,0,    0,0,    0,0,    0,0,    
  3772. 0,0,    0,0,    0,0,    40,40,    
  3773. 40,40,    40,40,    40,40,    40,40,    
  3774. 40,40,    40,40,    40,40,    40,40,    
  3775. 40,40,    40,40,    40,40,    40,40,    
  3776. 40,40,    40,40,    40,40,    40,40,    
  3777. 40,40,    40,40,    40,40,    40,40,    
  3778. 40,40,    40,40,    40,40,    40,40,    
  3779. 40,40,    0,0,    0,0,    0,0,    
  3780. 0,0,    0,0,    0,0,    40,40,    
  3781. 40,40,    40,40,    40,40,    40,40,    
  3782. 40,40,    40,40,    40,40,    40,40,    
  3783. 40,40,    40,40,    40,40,    40,40,    
  3784. 40,40,    40,40,    40,40,    40,40,    
  3785. 40,40,    40,40,    40,40,    40,40,    
  3786. 40,40,    40,40,    40,40,    40,40,    
  3787. 40,40,    43,43,    43,43,    43,43,    
  3788. 43,43,    43,43,    43,43,    43,43,    
  3789. 43,43,    43,43,    43,43,    0,0,    
  3790. 0,0,    0,0,    0,0,    0,0,    
  3791. 0,0,    0,0,    43,43,    43,43,    
  3792. 43,43,    43,43,    43,43,    43,43,    
  3793. 43,43,    43,43,    43,43,    43,43,    
  3794. 43,43,    43,43,    43,43,    43,43,    
  3795. 43,43,    43,43,    43,43,    43,43,    
  3796. 43,43,    43,43,    43,43,    43,43,    
  3797. 43,43,    43,43,    43,43,    43,43,    
  3798. 0,0,    0,0,    0,0,    0,0,    
  3799. 0,0,    0,0,    43,43,    43,43,    
  3800. 43,43,    43,43,    43,43,    43,43,    
  3801. 43,43,    43,43,    43,43,    43,43,    
  3802. 43,43,    43,43,    43,43,    43,43,    
  3803. 43,43,    43,43,    43,43,    43,43,    
  3804. 43,43,    43,43,    43,43,    43,43,    
  3805. 43,43,    43,43,    43,43,    43,43,    
  3806. 55,67,    55,67,    55,67,    55,67,    
  3807. 55,67,    55,67,    55,67,    55,67,    
  3808. 55,67,    55,67,    0,0,    0,0,    
  3809. 0,0,    0,0,    0,0,    0,0,    
  3810. 0,0,    55,67,    55,67,    55,67,    
  3811. 55,67,    55,67,    55,67,    55,67,    
  3812. 55,67,    55,67,    55,67,    55,67,    
  3813. 55,67,    55,67,    55,67,    55,67,    
  3814. 55,67,    55,67,    55,67,    55,67,    
  3815. 55,67,    55,67,    55,67,    55,67,    
  3816. 55,67,    55,67,    55,67,    56,68,    
  3817. 0,0,    56,56,    56,56,    56,56,    
  3818. 56,56,    56,56,    56,56,    56,56,    
  3819. 56,56,    56,56,    56,56,    0,0,    
  3820. 0,0,    0,0,    0,0,    0,0,    
  3821. 0,0,    0,0,    56,56,    56,56,    
  3822. 56,56,    56,56,    56,56,    56,56,    
  3823. 56,56,    56,56,    56,56,    56,56,    
  3824. 56,56,    56,56,    56,56,    56,56,    
  3825. 56,56,    56,56,    56,56,    56,56,    
  3826. 56,56,    56,56,    56,56,    56,56,    
  3827. 56,56,    56,56,    56,56,    56,56,    
  3828. 68,78,    68,78,    68,78,    68,78,    
  3829. 68,78,    68,78,    68,78,    68,78,    
  3830. 68,78,    68,78,    56,69,    0,0,    
  3831. 0,0,    0,0,    0,0,    0,0,    
  3832. 0,0,    68,78,    68,78,    68,78,    
  3833. 68,78,    68,78,    68,78,    68,78,    
  3834. 68,78,    68,78,    68,78,    68,78,    
  3835. 68,78,    68,78,    68,78,    68,78,    
  3836. 68,78,    68,78,    68,78,    68,78,    
  3837. 68,78,    68,78,    68,78,    68,78,    
  3838. 68,78,    68,78,    68,78,    69,79,    
  3839. 0,0,    69,79,    0,0,    0,0,    
  3840. 69,80,    69,80,    69,80,    69,80,    
  3841. 69,80,    69,80,    69,80,    69,80,    
  3842. 69,80,    69,80,    77,79,    0,0,    
  3843. 77,79,    0,0,    0,0,    77,87,    
  3844. 77,87,    77,87,    77,87,    77,87,    
  3845. 77,87,    77,87,    77,87,    77,87,    
  3846. 77,87,    79,87,    79,87,    79,87,    
  3847. 79,87,    79,87,    79,87,    79,87,    
  3848. 79,87,    79,87,    79,87,    80,80,    
  3849. 80,80,    80,80,    80,80,    80,80,    
  3850. 80,80,    80,80,    80,80,    80,80,    
  3851. 80,80,    0,0,    0,0,    0,0,    
  3852. 0,0};
  3853. struct yysvf yysvec[] ={
  3854. 0,    0,    0,
  3855. yycrank+-1,    0,        0,    
  3856. yycrank+-42,    yysvec+1,    0,    
  3857. yycrank+0,    0,        yyvstop+1,
  3858. yycrank+6,    0,        yyvstop+3,
  3859. yycrank+0,    0,        yyvstop+5,
  3860. yycrank+0,    0,        yyvstop+7,
  3861. yycrank+0,    0,        yyvstop+10,
  3862. yycrank+-80,    0,        yyvstop+13,
  3863. yycrank+-98,    0,        yyvstop+16,
  3864. yycrank+-121,    0,        yyvstop+18,
  3865. yycrank+0,    0,        yyvstop+20,
  3866. yycrank+0,    0,        yyvstop+23,
  3867. yycrank+0,    0,        yyvstop+26,
  3868. yycrank+0,    0,        yyvstop+29,
  3869. yycrank+154,    0,        yyvstop+32,
  3870. yycrank+229,    0,        yyvstop+36,
  3871. yycrank+0,    0,        yyvstop+38,
  3872. yycrank+307,    0,        yyvstop+41,
  3873. yycrank+0,    0,        yyvstop+43,
  3874. yycrank+382,    0,        yyvstop+46,
  3875. yycrank+2,    yysvec+20,    yyvstop+48,
  3876. yycrank+0,    0,        yyvstop+50,
  3877. yycrank+0,    0,        yyvstop+53,
  3878. yycrank+0,    0,        yyvstop+56,
  3879. yycrank+8,    yysvec+20,    yyvstop+59,
  3880. yycrank+8,    yysvec+20,    yyvstop+61,
  3881. yycrank+23,    yysvec+20,    yyvstop+63,
  3882. yycrank+4,    yysvec+20,    yyvstop+65,
  3883. yycrank+0,    0,        yyvstop+67,
  3884. yycrank+0,    0,        yyvstop+70,
  3885. yycrank+0,    0,        yyvstop+74,
  3886. yycrank+-496,    yysvec+8,    yyvstop+78,
  3887. yycrank+0,    0,        yyvstop+80,
  3888. yycrank+0,    yysvec+10,    0,    
  3889. yycrank+0,    0,        yyvstop+82,
  3890. yycrank+459,    0,        0,    
  3891. yycrank+0,    0,        yyvstop+84,
  3892. yycrank+495,    yysvec+20,    yyvstop+86,
  3893. yycrank+523,    yysvec+20,    yyvstop+88,
  3894. yycrank+566,    0,        yyvstop+90,
  3895. yycrank+0,    0,        yyvstop+92,
  3896. yycrank+0,    0,        yyvstop+94,
  3897. yycrank+641,    0,        yyvstop+96,
  3898. yycrank+13,    yysvec+43,    yyvstop+98,
  3899. yycrank+9,    yysvec+20,    yyvstop+100,
  3900. yycrank+6,    yysvec+20,    yyvstop+102,
  3901. yycrank+7,    yysvec+20,    yyvstop+104,
  3902. yycrank+21,    yysvec+20,    yyvstop+106,
  3903. yycrank+37,    yysvec+20,    yyvstop+108,
  3904. yycrank+27,    yysvec+20,    yyvstop+110,
  3905. yycrank+25,    yysvec+20,    yyvstop+112,
  3906. yycrank+42,    yysvec+36,    yyvstop+114,
  3907. yycrank+469,    0,        0,    
  3908. yycrank+505,    yysvec+20,    yyvstop+116,
  3909. yycrank+716,    0,        0,    
  3910. yycrank+761,    yysvec+20,    yyvstop+119,
  3911. yycrank+42,    yysvec+43,    yyvstop+122,
  3912. yycrank+33,    yysvec+20,    yyvstop+124,
  3913. yycrank+34,    yysvec+20,    yyvstop+126,
  3914. yycrank+0,    yysvec+20,    yyvstop+128,
  3915. yycrank+48,    yysvec+20,    yyvstop+131,
  3916. yycrank+43,    yysvec+20,    yyvstop+133,
  3917. yycrank+52,    yysvec+20,    yyvstop+135,
  3918. yycrank+53,    yysvec+20,    yyvstop+137,
  3919. yycrank+28,    yysvec+53,    0,    
  3920. yycrank+0,    yysvec+53,    yyvstop+139,
  3921. yycrank+113,    yysvec+55,    yyvstop+141,
  3922. yycrank+804,    0,        0,    
  3923. yycrank+852,    yysvec+20,    yyvstop+143,
  3924. yycrank+46,    yysvec+43,    yyvstop+145,
  3925. yycrank+41,    yysvec+20,    yyvstop+147,
  3926. yycrank+61,    yysvec+20,    yyvstop+149,
  3927. yycrank+85,    yysvec+20,    yyvstop+151,
  3928. yycrank+59,    yysvec+20,    yyvstop+154,
  3929. yycrank+54,    yysvec+20,    yyvstop+156,
  3930. yycrank+0,    yysvec+20,    yyvstop+158,
  3931. yycrank+867,    0,        0,    
  3932. yycrank+69,    yysvec+68,    yyvstop+161,
  3933. yycrank+877,    0,        0,    
  3934. yycrank+887,    yysvec+20,    yyvstop+163,
  3935. yycrank+67,    yysvec+43,    yyvstop+166,
  3936. yycrank+0,    yysvec+20,    yyvstop+168,
  3937. yycrank+0,    yysvec+20,    yyvstop+171,
  3938. yycrank+59,    yysvec+20,    yyvstop+174,
  3939. yycrank+58,    yysvec+20,    yyvstop+176,
  3940. yycrank+0,    yysvec+20,    yyvstop+178,
  3941. yycrank+0,    yysvec+79,    yyvstop+181,
  3942. yycrank+59,    yysvec+43,    yyvstop+183,
  3943. yycrank+65,    yysvec+20,    yyvstop+185,
  3944. yycrank+81,    yysvec+20,    yyvstop+187,
  3945. yycrank+74,    yysvec+43,    yyvstop+189,
  3946. yycrank+81,    yysvec+20,    yyvstop+191,
  3947. yycrank+73,    yysvec+20,    yyvstop+193,
  3948. yycrank+64,    yysvec+43,    yyvstop+195,
  3949. yycrank+82,    yysvec+20,    yyvstop+197,
  3950. yycrank+77,    yysvec+20,    yyvstop+199,
  3951. yycrank+84,    yysvec+43,    yyvstop+201,
  3952. yycrank+72,    yysvec+20,    yyvstop+203,
  3953. yycrank+0,    yysvec+20,    yyvstop+205,
  3954. yycrank+0,    yysvec+43,    yyvstop+208,
  3955. yycrank+73,    yysvec+20,    yyvstop+211,
  3956. yycrank+0,    yysvec+20,    yyvstop+213,
  3957. 0,    0,    0};
  3958. struct yywork *yytop = yycrank+944;
  3959. struct yysvf *yybgin = yysvec+1;
  3960. char yymatch[] ={
  3961. 00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  3962. 01  ,011 ,012 ,01  ,01  ,01  ,01  ,01  ,
  3963. 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  3964. 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  3965. 011 ,01  ,01  ,01  ,01  ,01  ,01  ,047 ,
  3966. '(' ,'(' ,01  ,'+' ,01  ,'+' ,'(' ,01  ,
  3967. '0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
  3968. '0' ,'0' ,01  ,01  ,01  ,01  ,01  ,01  ,
  3969. 01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
  3970. 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
  3971. 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
  3972. 'A' ,'A' ,'A' ,'(' ,01  ,01  ,01  ,01  ,
  3973. 01  ,'a' ,'a' ,'a' ,'a' ,'a' ,'a' ,'a' ,
  3974. 'a' ,'a' ,'a' ,'a' ,'a' ,'a' ,'a' ,'a' ,
  3975. 'a' ,'a' ,'a' ,'a' ,'a' ,'a' ,'a' ,'a' ,
  3976. 'a' ,'a' ,'a' ,01  ,01  ,01  ,01  ,01  ,
  3977. 0};
  3978. char yyextra[] ={
  3979. 0,0,0,0,0,0,0,0,
  3980. 0,0,0,0,0,0,0,0,
  3981. 0,0,0,0,0,0,0,0,
  3982. 0,0,0,0,0,0,0,0,
  3983. 0,0,0,0,0,0,0,0,
  3984. 0};
  3985. /*    ncform    4.1    83/08/11    */
  3986.  
  3987. int yylineno =1;
  3988. # define YYU(x) x
  3989. # define NLSTATE yyprevious=YYNEWLINE
  3990. char yytext[YYLMAX];
  3991. struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
  3992. char yysbuf[YYLMAX];
  3993. char *yysptr = yysbuf;
  3994. int *yyfnd;
  3995. extern struct yysvf *yyestate;
  3996. int yyprevious = YYNEWLINE;
  3997. yylook(){
  3998.     register struct yysvf *yystate, **lsp;
  3999.     register struct yywork *yyt;
  4000.     struct yysvf *yyz;
  4001.     int yych;
  4002.     struct yywork *yyr;
  4003. # ifdef LEXDEBUG
  4004.     int debug;
  4005. # endif
  4006.     char *yylastch;
  4007.     /* start off machines */
  4008. # ifdef LEXDEBUG
  4009.     debug = 0;
  4010. # endif
  4011.     if (!yymorfg)
  4012.         yylastch = yytext;
  4013.     else {
  4014.         yymorfg=0;
  4015.         yylastch = yytext+yyleng;
  4016.         }
  4017.     for(;;){
  4018.         lsp = yylstate;
  4019.         yyestate = yystate = yybgin;
  4020.         if (yyprevious==YYNEWLINE) yystate++;
  4021.         for (;;){
  4022. # ifdef LEXDEBUG
  4023.             if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
  4024. # endif
  4025.             yyt = yystate->yystoff;
  4026.             if(yyt == yycrank){        /* may not be any transitions */
  4027.                 yyz = yystate->yyother;
  4028.                 if(yyz == 0)break;
  4029.                 if(yyz->yystoff == yycrank)break;
  4030.                 }
  4031.             *yylastch++ = yych = input();
  4032.         tryagain:
  4033. # ifdef LEXDEBUG
  4034.             if(debug){
  4035.                 fprintf(yyout,"char ");
  4036.                 allprint(yych);
  4037.                 putchar('\n');
  4038.                 }
  4039. # endif
  4040.             yyr = yyt;
  4041.             if ( (int)yyt > (int)yycrank){
  4042.                 yyt = yyr + yych;
  4043.                 if (yyt <= yytop && yyt->verify+yysvec == yystate){
  4044.                     if(yyt->advance+yysvec == YYLERR)    /* error transitions */
  4045.                         {unput(*--yylastch);break;}
  4046.                     *lsp++ = yystate = yyt->advance+yysvec;
  4047.                     goto contin;
  4048.                     }
  4049.                 }
  4050. # ifdef YYOPTIM
  4051.             else if((int)yyt < (int)yycrank) {        /* r < yycrank */
  4052.                 yyt = yyr = yycrank+(yycrank-yyt);
  4053. # ifdef LEXDEBUG
  4054.                 if(debug)fprintf(yyout,"compressed state\n");
  4055. # endif
  4056.                 yyt = yyt + yych;
  4057.                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
  4058.                     if(yyt->advance+yysvec == YYLERR)    /* error transitions */
  4059.                         {unput(*--yylastch);break;}
  4060.                     *lsp++ = yystate = yyt->advance+yysvec;
  4061.                     goto contin;
  4062.                     }
  4063.                 yyt = yyr + YYU(yymatch[yych]);
  4064. # ifdef LEXDEBUG
  4065.                 if(debug){
  4066.                     fprintf(yyout,"try fall back character ");
  4067.                     allprint(YYU(yymatch[yych]));
  4068.                     putchar('\n');
  4069.                     }
  4070. # endif
  4071.                 if(yyt <= yytop && yyt->verify+yysvec == yystate){
  4072.                     if(yyt->advance+yysvec == YYLERR)    /* error transition */
  4073.                         {unput(*--yylastch);break;}
  4074.                     *lsp++ = yystate = yyt->advance+yysvec;
  4075.                     goto contin;
  4076.                     }
  4077.                 }
  4078.             if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
  4079. # ifdef LEXDEBUG
  4080.                 if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
  4081. # endif
  4082.                 goto tryagain;
  4083.                 }
  4084. # endif
  4085.             else
  4086.                 {unput(*--yylastch);break;}
  4087.         contin:
  4088. # ifdef LEXDEBUG
  4089.             if(debug){
  4090.                 fprintf(yyout,"state %d char ",yystate-yysvec-1);
  4091.                 allprint(yych);
  4092.                 putchar('\n');
  4093.                 }
  4094. # endif
  4095.             ;
  4096.             }
  4097. # ifdef LEXDEBUG
  4098.         if(debug){
  4099.             fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
  4100.             allprint(yych);
  4101.             putchar('\n');
  4102.             }
  4103. # endif
  4104.         while (lsp-- > yylstate){
  4105.             *yylastch-- = 0;
  4106.             if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
  4107.                 yyolsp = lsp;
  4108.                 if(yyextra[*yyfnd]){        /* must backup */
  4109.                     while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
  4110.                         lsp--;
  4111.                         unput(*yylastch--);
  4112.                         }
  4113.                     }
  4114.                 yyprevious = YYU(*yylastch);
  4115.                 yylsp = lsp;
  4116.                 yyleng = yylastch-yytext+1;
  4117.                 yytext[yyleng] = 0;
  4118. # ifdef LEXDEBUG
  4119.                 if(debug){
  4120.                     fprintf(yyout,"\nmatch ");
  4121.                     sprint(yytext);
  4122.                     fprintf(yyout," action %d\n",*yyfnd);
  4123.                     }
  4124. # endif
  4125.                 return(*yyfnd++);
  4126.                 }
  4127.             unput(*yylastch);
  4128.             }
  4129.         if (yytext[0] == 0  /* && feof(yyin) */)
  4130.             {
  4131.             yysptr=yysbuf;
  4132.             return(0);
  4133.             }
  4134.         yyprevious = yytext[0] = input();
  4135.         if (yyprevious>0)
  4136.             output(yyprevious);
  4137.         yylastch=yytext;
  4138. # ifdef LEXDEBUG
  4139.         if(debug)putchar('\n');
  4140. # endif
  4141.         }
  4142.     }
  4143. yyback(p, m)
  4144.     int *p;
  4145. {
  4146. if (p==0) return(0);
  4147. while (*p)
  4148.     {
  4149.     if (*p++ == m)
  4150.         return(1);
  4151.     }
  4152. return(0);
  4153. }
  4154.     /* the following are only used in the lex library */
  4155. yyinput(){
  4156.     return(input());
  4157.     }
  4158. yyoutput(c)
  4159.   int c; {
  4160.     output(c);
  4161.     }
  4162. yyunput(c)
  4163.    int c; {
  4164.     unput(c);
  4165.     }
  4166. End
  4167. echo unbundling uchar.c 1>&2
  4168. cat >uchar.c <<'End'
  4169. # include "env.h"
  4170. main() {
  4171.   int i;
  4172.   uchar c;
  4173.  
  4174.    i = 250;
  4175.    c = itouc(i);
  4176.    i = uctoi(c);
  4177.    if (i == 250) printf("success\n");
  4178.    else printf("failure\n");
  4179. }
  4180.  
  4181. End
  4182.